Skip to content

BUG: groupby with levels on duplicated multi-index #10417

Closed
@vumaasha

Description

@vumaasha
x = pd.DataFrame({'x':[1,1,3,3],'y':[3,3,5,5]},index=[11,11,12,12])
y = x.stack()
print(y)
print(y.groupby(level=[0,1]).sum())

Ouput

11  x    1
    y    3
    x    1
    y    3
12  x    3
    y    5
    x    3
    y    5
dtype: int64
11  x    1
    y    3
    x    1
    y    3
12  x    3
    y    5
    x    3
    y    5
dtype: int64

The stack and group by sum are just the same.

Expected output:

11  x    2
11  y    6
12  x    6
12  y    10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions