machinery
machinery

Reputation: 6290

Taking mean of means of groups

I have a Pandas dataframe with several columns and several rows. I would like to group by a column called "A". I can do this by df.groupby('A'). Now I would like to take the means of column called "C" of each group which I can do with df.groupby('A').C.mean(). Finally, I would like to take the mean of the means of each group for column C.

How can I achieve this (the final result should just be one integer, i.e. the mean of the means of each group)?

Upvotes: 0

Views: 73

Answers (1)

koPytok
koPytok

Reputation: 3733

Just add another mean:

df.groupby('A').C.mean().mean()

Upvotes: 1

Related Questions