Skip to content

BUG/ENH: groupby head returns empty result for negative n #9214

@TomAugspurger

Description

@TomAugspurger

More drive-by reports. I'll try to close some of these issues sometime...

In [8]: s = pd.Series(np.random.randn(10))

In [9]: s.groupby(s > 0).apply(lambda x: x.head(-1))  # works nicely
Out[9]:
False  0   -0.277400
       1   -0.875231
       3   -0.315087
       4   -0.966649
       6   -0.474389
       7   -0.121225
True   2    0.237861
       5    1.311601
dtype: float64

In [10]: s.groupby(s > 0).head(-1)  # doesn't.
Out[10]: Series([], dtype: float64)

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