pandas get column average/mean

We Are Going To Discuss About pandas get column average/mean. So lets Start this Python Article.

pandas get column average/mean

How to solve pandas get column average/mean

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

pandas get column average/mean

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

Original Author DSM Of This Content

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.

Original Author Chandu Of This Content

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.

Original Author nainometer Of This Content

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

Original Author Hrvoje Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment