To group by in group by and average with Python Pandas, we can use the mean
method.
For instance, we write
df.groupby(['org']).mean().groupby(['cluster']).mean()
to call groupby
to group values by the org
column value.
And then we call mean
to get the mean of the grouped values.
Then we call groupby
again to group the returned values by the cluster
column.
And finally we call mean
again to get the mean of those grouped values.