Categories
Python Answers

How to group by in group by and average with Python Pandas?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *