Pandas Series function agg() in Python
The Pandas Series function agg() used to aggregate using one or more operations over the specified axis. It returns either scalar, Series or DataFrame object.
Syntax
 1 Series.agg(func = None, axis = 0, *args, **kwargs)
 2 # or - alias
 3 Series.aggregate(func = None, axis = 0, *args, **kwargs)
func : It is a function, string, list or dict that used to for aggregating the data. If a function, it must either work when passed a Series or when passed to Series.apply().
axis : It is either string or an integer that specifies the axis for the function to applied. It can be either 0 or 'index' and not specified the default value will be 0.
args It specifies the positional argument passed to func after the series value.
**kwargs : It specifies the additional keyword arguments passed to func.
agg() function
 1 import pandas as pd
 2 
 3 ser = pd.Series([2, 3, 5, 7])
 4 res = ser.agg(min)
 5 
 6 print('The aggregated min of Series object is :')
 7 print(res)
In the above example, a Series object is created by passing an array. A agg() function is called by passing pandas min() function that find the minimum value and assign to the variable that will be printed on console.
Output
 1 The aggregated min of Series object is :
 2 2

agg() with list

agg() with list
 1 import pandas as pd
 2 
 3 ser = pd.Series([2, 3, 5, 7])
 4 res = ser.agg(['min', 'max'])
 5 
 6 print('The aggregated min of Series object is :')
 7 print(res)
In the above example, a agg() function is called by passing a list of functions. It perform specified operations and returns the DataFrame object. The result is assigned to the variable that will be printed on console.
Output
 1 The aggregated min of Series object is :
 2 min    2
 3 max    7
 4 dtype: int64
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us