Skip to content

BUG? DataFrame.groupby.apply result has unexpected index #9704

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

Closed
shoyer opened this issue Mar 23, 2015 · 1 comment · Fixed by #34998
Closed

BUG? DataFrame.groupby.apply result has unexpected index #9704

shoyer opened this issue Mar 23, 2015 · 1 comment · Fixed by #34998
Labels
Apply Apply, Aggregate, Transform, Map Bug Groupby
Milestone

Comments

@shoyer
Copy link
Member

shoyer commented Mar 23, 2015

Compare the output of these three groupby/apply calls:

In [66]: df = pd.DataFrame({'a': [1, 1, 2, 2], 'b': range(4)})

In [67]: df
Out[67]:
   a  b
0  1  0
1  1  1
2  2  2
3  2  3

In [68]: df.groupby('a')['b'].apply(lambda x: 2 * x)
Out[68]:
0    0
1    2
2    4
3    6
dtype: int64

In [69]: df.groupby('a').apply(lambda x: 2 * x)['b']
Out[69]:
0    0
1    2
2    4
3    6
Name: b, dtype: int64

In [70]: df.groupby('a').apply(lambda x: 2 * x['b'])
Out[70]:
a
1  0    0
   1    2
2  2    4
   3    6
Name: b, dtype: int64

The first two are what I expected; the last is not -- I expected the same result as the previous two.

@jreback jreback added this to the Next Major Release milestone Mar 23, 2015
@jreback
Copy link
Contributor

jreback commented Mar 23, 2015

warning, this is a rabbit hole.....

@mroeschke mroeschke added the Apply Apply, Aggregate, Transform, Map label Oct 26, 2019
@mroeschke mroeschke added Bug and removed API Design labels Jun 28, 2020
@jreback jreback modified the milestones: Contributions Welcome, 1.5 Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Bug Groupby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants