To find mean of DataFrame, use Pandas DataFrame. mean() function. The DataFrame. mean() function returns the mean of the values for the requested axis.
mean() You're anything but average! Jokes aside, Pandas Mean is a fundamental function that is in every data scientist's, analyst's, and data monkey's toolkit. Pandas Mean will return the average of your data across a specified axis.
How to find the mean row wise in Pandas? It returns the mean for each row with axis=1 . Note that the pandas mean() function calculates the mean for columns and not rows by default. Thus, make sure to pass 1 to the axis parameter if you want the get the average for each row.
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
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.
Do try to give print (df.describe())
a shot. I hope it will be very helpful to get an overall description of your dataframe.
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
you can use
df.describe()
you will get basic statistics of the dataframe and to get mean of specific column you can use
df["columnname"].mean()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With