Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropping invalid columns FutureWarning

Tags:

python

pandas

# 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?

like image 461
Максим Avatar asked Feb 20 '26 18:02

Максим


2 Answers

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)
like image 115
Phoenix Avatar answered Feb 23 '26 06:02

Phoenix


Just mention numeric_only=True inside the braces of mean, max, sum, etc. Earlier, this was set default as True but now the default would be False.

like image 32
Minhaz Uddin Avatar answered Feb 23 '26 07:02

Minhaz Uddin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!