# 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())
Run Code Online (Sandbox Code Playgroud)
我正在使用我的数据框进行操作并收到此警告。我可以以某种方式摆脱这个警告吗?
Ham*_*zah 22
您的数据框中有一些列不是数字列。mean()
对这些列使用或无效max()
。要按照警告消息的建议删除这些警告,您应该使用numeric_only
属性来仅应用max
和mean()
用于数字列。
你可以试试这个:
sunny_daily_max = sunny.resample('D').max(numeric_only=True)
sunny_daily_max.mean(numeric_only=True)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
27193 次 |
最近记录: |