Skip to content
Advertisement

Why Pandas gives AttributeError: ‘SeriesGroupBy’ object has no attribute ‘pct’?

I’m trying to pass a user defined function pct to Pandas agg method, and it works if I only pass that function but it doesn’t when I use the dictionary format for defining the functions. Does anyone know why?

JavaScript

returns as expected

JavaScript

But

JavaScript

returns the following error:

JavaScript

Advertisement

Answer

There is string 'pct', need variable pct – lambda function by removing '':

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement