Skip to content

'mode' not recognized by df.groupby().agg(), but pd.Series.mode works #11562

@patricksurry

Description

@patricksurry

This works:

df = pd.DataFrame({'A': [1, 2, 1, 2, 1, 2, 3], 'B': [1, 1, 1, 2, 2, 2, 2]})
df.groupby('B').agg(pd.Series.mode)

but this doesn't:

df.groupby('B').agg('mode')

...
AttributeError: Cannot access callable attribute 'mode' of 'DataFrameGroupBy' objects, try using the 'apply' method

I thought all the series aggregate methods propagated automatically to groupby, but I've probably misunderstood?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions