我无法在pandas中获取一列的平均值。我有一个数据框。我尝试以下两种方法都无法给出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
以下返回多个值,而不是一个:
allDF[['weight']].mean(axis=1)
那么这样做也可以:
allDF.groupby('weight').mean()
df.groupby('weight')
wasn't what you wanted, because it split the df into separate columns, each with a distinct value of weight. Instead of justdf['weight'].mean()
- smci