Tutorials References Exercises Sign Up Menu
Create Website Get Certified Pro

Pandas DataFrame agg() Method

❮ DataFrame Reference


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"])

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.


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


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
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