dataframe groupby multiple columns

Do you want to know the details regarding “dataframe groupby multiple columns”. If yes, you’re in the correct post.

dataframe groupby multiple columns

grouped_multiple = df.groupby(['Team', 'Pos']).agg('Age': ['mean', 'min', 'max'])
grouped_multiple.columns = ['age_mean', 'age_min', 'age_max']
grouped_multiple = grouped_multiple.reset_index()
In [8]: grouped = df.groupby('A')

In [9]: grouped = df.groupby(['A', 'B'])
In [11]: df.groupby(['col5', 'col2']).size()
col5  col2
1     A       1
      D       3
2     B       2
3     A       3
      C       1
4     B       1
5     B       2
6     B       1
dtype: int64

Final Thoughts

I hope this tutorial helps you to know about “dataframe groupby multiple columns”. If you have any doubts regarding this post please let us know via the comment section. Share this article with your friends and family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment