Pandas: Compute The Mean Of A Column Grouped By Another Column
Say I have a dataframe like this: gender height weight C 2000-01-01 male 42.849980 157.500553 1 2000-01-02 male 49.607315 177.340407 1 2000-01-03
Solution 1:
Your syntax is incorrect, there is no groupby
arg for mean
, you want to groupby
on the col of interest and then call mean
on the column of interest:
In [11]:
df.groupby('C')['height'].mean()
Out[11]:
C
1 54.299919
2 52.760444
3 67.672566
Name: height, dtype: float64
Post a Comment for "Pandas: Compute The Mean Of A Column Grouped By Another Column"