Skip to content

groupby with as_index=False, inconsistency between max and idxmax #8582

Closed
@behzadnouri

Description

@behzadnouri
>>> df = pd.DataFrame(np.random.randint(0, 100, (50, 2)), columns=['jim', 'joe'])
>>> ts = pd.Series(np.random.randint(0, 3, 50))
>>> df.groupby(ts, as_index=False).idxmax()
   jim  joe
0   25   36
1   22    5
2    3    4
>>> df.groupby(ts, as_index=False).max()
   NaN  jim  joe
0    0   93   94
1    1   94   89
2    2   85   93

max adds the grouper to the result frame, whereas idxmax doesn't.

The API documentation says:

as_index=False is effectively “SQL-style” grouped output

so i would assume, it should not inject a new column with NaN name.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions