Reputation: 159
id gender status dept var1 var2 salary
0 P001 M FT DS 2.0 8.0 NaN
1 P002 F PT FS 3.0 NaN 54.0
2 P003 M NaN AWS 5.0 5.0 59.0
3 P004 F FT AWS NaN 8.0 120.0
4 P005 M PT DS 7.0 11.0 58.0
5 P006 F PT NaN 1.0 NaN 75.0
6 P007 M FT FS NaN NaN NaN
7 P008 F NaN FS 10.0 2.0 136.0
8 P009 M PT NaN 14.0 3.0 60.0
9 P010 F FT DS NaN 7.0 125.0
10 P011 M NaN AWS 6.0 9.0 NaN
print(df.mean())
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(df.mean())
when corrected my code as :
print(df.mean(numeric_only=True))
I solve it , without an error.
Is there any other way to solve it ?
Upvotes: 13
Views: 37112
Reputation: 1
Try this:
import pandas as pd
pd.options.mode.chained_assignment = None
Upvotes: -1
Reputation:
No, there's no other way to solve it. Using numeric_only=True
is the right way.
You're getting that warning because there are some columns that contain strings, but df.mean()
only works with columns that contain numbers (floats, ints, nan, etc.).
Using numeric_only=True
causes df.mean()
to ignore columns that contain non-numbers, and only calculate the mean for columns that only contain numbers.
Upvotes: 21