Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Pandas DataFrame agg() Method

❮ DataFrame Reference


Example

Return the sum of each row:

import pandas as pd

data = {
  "x": [50, 40, 30],
  "y": [300, 1112, 42]
}

df = pd.DataFrame(data)

x = df.agg(["sum"])

print(x)
Try it Yourself »

Definition and Usage

The agg() method allows you to apply a function or a list of function names to be executed along one of the axis of the DataFrame, default 0, which is the index (row) axis.

Note: the agg() method is an alias of the aggregate() method.


Syntax

dataframe.agg(func, axis, args, kwargs)

Parameters

The axis parameter is a keyword argument.

Parameter Value Description
func   Required. A function, function name, or a list of function names to apply to the DataFrame.
axis 0
1
'index'
'columns'
Optional, Which axis to apply the function to. default 0.
args   Optional, arguments to send into the function
kwargs   Optional, keyword arguments to send into the function

Return Value

A DataFrame or a Series object, with the changes.

This function does NOT make changes to the original DataFrame object.


❮ DataFrame Reference