# Select days that are sunny: sunny
sunny = df_clean.loc[df_clean['sky_condition']=='CLR']
# Select days that are overcast: overcast
overcast = df_clean.loc[df_clean['sky_condition'].str.contains('OVC')]
# Resample sunny and overcast, aggregating by maximum daily temperature
sunny_daily_max = sunny.resample('D').max()
overcast_daily_max = overcast.resample('D').max()
# Print the difference between the mean of sunny_daily_max and overcast_daily_max
print(sunny_daily_max.mean() - overcast_daily_max.mean())
/tmp/ipykernel_1065/1054523508.py:9: FutureWarning: Dropping invalid columns in
DataFrameGroupBy.max is deprecated. In a future version, a TypeError will be raised. Before
calling .max, select only columns which should be valid for the function.
overcast_daily_max = overcast.resample('D').max()
/tmp/ipykernel_1065/1054523508.py:12: FutureWarning: Dropping of nuisance columns in DataFrame
reductions (with 'numeric_only=None') is deprecated; in a future version this will raise
TypeError. Select only valid columns before calling the reduction.
print(sunny_daily_max.mean() - overcast_daily_max.mean())
我正在使用我的数据框进行操作并收到此警告。我可以以某种方式摆脱这个警告吗?
数据框中的某些列不是数字列。对这些列使用
mean()
或 max()
无效。要按照警告消息的建议删除这些警告,您应该使用 numeric_only
属性仅对数字列应用 max
和 mean()
。
你可以试试这个:
sunny_daily_max = sunny.resample('D').max(numeric_only=True)
sunny_daily_max.mean(numeric_only=True)
只需在平均值、最大值、总和等的大括号内提及 numeric_only=True 即可。 早些时候,默认设置为 True,但现在默认为 False。