首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >消除未来预警

消除未来预警
EN

Stack Overflow用户
提问于 2022-05-20 00:22:44
回答 1查看 358关注 0票数 0
代码语言:javascript
复制
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))

我得到了

代码语言:javascript
复制
/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'])`

如果我第二次运行这段代码,它会在没有运行代码的情况下工作。但我需要在第一次没有任何警告的情况下开始工作。我很高兴有任何可能的解决办法来解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2022-05-20 04:56:19

使用select_dtypes只保留数字列:

代码语言:javascript
复制
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只应包含数字值,则本列中有错误。在这种情况下,使用:

代码语言:javascript
复制
sunny['visibility'] = pd.to_numeric(sunny['visibility'], errors='coerce')


overcast['visibility'] = pd.to_numeric(overcast['visibility'], errors='coerce')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72312334

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档