1

I am trying to use the pandas NamedAgg function and am hitting a wall with it. I am getting the "module 'pandas' has no attribute 'NamedAgg'" error message.

I am using the example in the documentation, copied and pasted, so I don't know what I am doing wrong. Any advice?

pandas problem with NamedAgg

Community
  • 1
  • 1
ingrid
  • 47
  • 1
  • 7

1 Answers1

5

You have to upgrade to pandas 0.25+, Groupby aggregation with relabeling or named aggregation:

New in version 0.25.0.

To support column-specific aggregation with control over the output column names, pandas accepts the special syntax in GroupBy.agg(), known as "named aggregation", where

  • The keywords are the output column names
  • The values are tuples whose first element is the column to select and the second element is the aggregation to apply to that column. Pandas provides the pandas.NamedAgg namedtuple with the fields ['column', 'aggfunc'] to make it clearer what the arguments are. As usual, the aggregation can be a callable or a string alias.
Community
  • 1
  • 1
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • Many thanks for the answer., I just tried updating using pip, '!pip install pandas update 0.25.0' but is is saying version 0.25.0 is not available. Should I do it some other way? – ingrid Oct 07 '19 at 06:14
  • @ingrid - can you check [this](https://stackoverflow.com/questions/37954195/upgrade-version-of-pandas) ? – jezrael Oct 07 '19 at 06:17
  • it ok, sorry, I figured it out. Thanks for the answer. – ingrid Oct 07 '19 at 06:23