pandas get column average/mean
Solution 1:
If you only want the mean of the weight
column, select the column (which is a Series) and call .mean()
:
In [479]: df
Out[479]:
ID birthyear weight
0 619040 1962 0.123123
1 600161 1963 0.981742
2 25602033 1963 1.312312
3 624870 1987 0.942120
In [480]: df["weight"].mean()
Out[480]: 0.83982437500000007
Solution 2:
Try df.mean(axis=0)
, axis=0
argument calculates the column wise mean of the dataframe so the result will be axis=1
is row wise mean so you are getting multiple values.
Solution 3:
Do try to give print (df.describe())
a shot. I hope it will be very helpful to get an overall description of your dataframe.
Solution 4:
Mean for each column in df
:
A B C
0 5 3 8
1 5 3 9
2 8 4 9
df.mean()
A 6.000000
B 3.333333
C 8.666667
dtype: float64
and if you want average of all columns:
df.stack().mean()
6.0