Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vumaasha opened this issue Jun 23, 2015 · 1 comment · Fixed by #10433
Closed

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

vumaasha opened this issue Jun 23, 2015 · 1 comment · Fixed by #10433
Milestone

Comments

@vumaasha
Copy link

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
@jreback
Copy link
Contributor

jreback commented Jun 23, 2015

yep, looks a little buggy. As the following gives the expected output.

In [5]: y.reset_index().groupby(['level_0','level_1']).sum()
Out[5]: 
                  0
level_0 level_1    
11      x         2
        y         6
12      x         6
        y        10

@jreback jreback changed the title stack + group by does not work as expected in 0.16.2 BUG: groupby with levels on duplicated multi-index Jun 23, 2015
@jreback jreback added this to the 0.17.0 milestone Jun 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants