Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to combine Groupby and Multiple Aggregate Functions in Pandas?

  • Difficulty Level : Easy
  • Last Updated : 10 May, 2020

Pandas is a Python package that offers various data structures and operations for manipulating numerical data and time series. It is mainly popular for importing and analyzing data much easier. It is an open-source library that is built on top of NumPy library.


Pandas dataframe.groupby() function is used to split the data in dataframe into groups based on a given condition.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Example 1:

# import library
import pandas as pd
# import csv file
df = pd.read_csv("")


Example 2:

# Find the average of each continent
# by grouping the data  
# based on the "continent".



Pandas dataframe.agg() function is used to do one or more operations on data based on specified axis


# here sum, minimum and maximum of column 
# beer_servings is calculatad
df.beer_servings.agg(["sum", "min", "max"])


Using These two functions together: We can find multiple aggregation functions of a particular column grouped by another column.


# find an aggregation of column "beer_servings"
# by grouping the "continent" column.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!