sunny = df_clean.loc[df_clean['sky_condition'] == 'CLR']
overcast = df_clean.loc[df_clean['sky_condition'].str.contains('OVC')]
sunny_daily_max = sunny.resample('D').agg(['max'])
overcast_daily_max = overcast.resample('D').agg(['max'])
print(sunny_daily_max.mean(numeric_only=True) - overcast_daily_max.mean(numeric_only=True))我得到了
/tmp/ipykernel_831/2080168548.py:9: FutureWarning: ['visibility'] did not aggregate successfully. If any error is raised this will raise in a future version of pandas. Drop these columns/ops to avoid this warning.
sunny_daily_max = sunny.resample('D').agg(['max']) /tmp/ipykernel_831/2080168548.py:10: FutureWarning: ['visibility'] did not aggregate successfully. If any error is raised this will raise in a future version of pandas. Drop these columns/ops to avoid this warning.
overcast_daily_max = overcast.resample('D').agg(['max'])`如果我第二次运行这段代码,它会在没有运行代码的情况下工作。但我需要在第一次没有任何警告的情况下开始工作。我很高兴有任何可能的解决办法来解决这个问题。
发布于 2022-05-20 04:56:19
使用select_dtypes只保留数字列:
sunny = df_clean.loc[df_clean['sky_condition'] == 'CLR'].select_dtypes('number')
overcast = df_clean.loc[df_clean['sky_condition'].str.contains('OVC')].select_dtypes('number')如果visibility只应包含数字值,则本列中有错误。在这种情况下,使用:
sunny['visibility'] = pd.to_numeric(sunny['visibility'], errors='coerce')
overcast['visibility'] = pd.to_numeric(overcast['visibility'], errors='coerce')https://stackoverflow.com/questions/72312334
复制相似问题