'Dropping invalid columns FutureWarning
# 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())
I'm making manipulations with my dataframe and getting this warning. Can i somehow get rid of this warning?
Solution 1:[1]
You have some columns in your dataframes are not numeric columns. It is invalid to use mean()
or max()
for these columns. To remove these warnings, as suggested by the warning message, you should use numeric_only
attribute to apply max
and mean()
for numeric columns only.
You can try this:
sunny_daily_max = sunny.resample('D').max(numeric_only=True)
sunny_daily_max.mean(numeric_only=True)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |