Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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

Your (@Rutger) suggestion works but would require a second step changing names to ['x','y','z']. I think the idea with named agg is doing agg and assigning names in one go. My example is taken from Pandas Docs and I am surprised it is not working. – Espen Seidel Jun 19, 2021 at 4:51 Very strange indeed. I tried the code and it works fine. It was introduced in Pandas 0.25. Is it possible that your code is run with a different venv or Python version than the one you are checking? – Rutger Jun 19, 2021 at 14:41 how can I check what you ask for? When I launch Spyder the console prompts Python 3.8.3 and pd.__version__ yields 1.0.5. The thing is I get the exact same error message from my home computer with Python 3.7.10 and pandas 1.0.1 in Google Colab the code run as expected – Espen Seidel Jun 20, 2021 at 12:01 It's strange, it really does seem that you checked everything. You can try to update all packages with Anaconda. If that does not work I would suggest using the old code with the renaming. Not as short as the code that should work of course... – Rutger Jun 21, 2021 at 7:22

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.