Named aggregation of df (not grouped) throwing error: 'TypeError: aggregate() missing 1 required positional argument: 'func''

Viewed 206

When I reproduce the example with named aggregation of a dataframe from the documentation I get an error. Docs: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.aggregate.html I am running Spyder 4.2.5 with Python 3.7 and also get the same error on a different computer with Python 3.8 and Jupyter Notebook with Python 3. Pandas version 1.0.5.

Reproduceable code:

import pandas as pd
import numpy as np
df = pd.DataFrame([[1, 2, 3],
                   [4, 5, 6],
                   [7, 8, 9],
                   [np.nan, np.nan, np.nan]],
                  columns=['A', 'B', 'C'])
df.agg(x=('A', max), y=('B', 'min'), z=('C', np.mean))

What am I missing?

Output: TypeError: aggregate() missing 1 required positional argument: 'func'

Disclaimer: First post on stackoverflow

1 Answers

The function argument needs only 1 value like a dictionary. See below.

df.agg(dict(A=max, B=min, C=np.mean))
Related