Skip to content

BUG: GroupBy.size incorrect for axis=1 #45715

Closed
@rhshadrach

Description

@rhshadrach

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

df = DataFrame({'a': [1, 1, 1], 'b': 2, 'c': 3, 'd': 4, 'e': 5})
gb = df.groupby([0, 0, 0, 1, 1], axis=1)
print(df)
print()
print(gb.size())

Issue Description

I can't imagine this being a useful op, but we still shouldn't have wrong results.

   a  b  c  d  e
0  1  2  3  4  5
1  1  2  3  4  5
2  1  2  3  4  5

0    3
1    2

Expected Behavior

    0  1
0   3  2
1   3  2
2   3  2

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions