Skip to content

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

Closed
@shoyer

Description

@shoyer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapBugGroupby

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions