pandas 获得列平均值/平均值 [英] pandas get column average/mean
本文介绍了 pandas 获得列平均值/平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法获得大熊猫中某列的平均值或均值.有一个数据框.我在下面尝试的任何事情都没有给我列weight
I can't get the average or mean of a column in pandas. A have a dataframe. Neither of things I tried below gives me the average of the column weight
>>> allDF
ID birthyear weight
0 619040 1962 0.1231231
1 600161 1963 0.981742
2 25602033 1963 1.3123124
3 624870 1987 0.94212
以下返回几个值,而不是一个:
The following returns several values, not one:
allDF[['weight']].mean(axis=1)
这也是如此:
allDF.groupby('weight').mean()
推荐答案
如果只希望weight
列的均值,请选择该列(为Series)并调用.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 获得列平均值/平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文