I try to compute the average size of a population composed of men and women:
>>> import pandas as pd
>>> df = pd.DataFrame([[175 , 'male' ], [181 , 'male' ], [165 , 'female' ], [179 , 'male' ], [156 , 'female' ]], columns=['size', 'sex'])
>>> df.head()
size sex
0 175 male
1 181 male
2 165 female
3 179 male
4 156 female
I would like to use Pandas groupby method to compute the average. Therefore, the following command returns an error:
>>> df.groupby('sex').size.mean()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-17-a31e7f02b69d> in <module>()
----> 1 df.groupby('sex').size.mean()
AttributeError: 'function' object has no attribute 'mean'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…