hipdf.core.groupby.SeriesGroupBy.tail#
19 min read time
Applies to Linux
- SeriesGroupBy.tail(n: int = 5, *, preserve_order: bool = True)#
Return last n rows of each group
Parameters#
- n
If positive: number of entries to include from end of group If negative: number of entries to exclude from start of group
- preserve_order
If True (default), return the n rows from each group in original dataframe order (this mimics pandas behavior though is more expensive). If you don’t need rows in original dataframe order you will see a performance improvement by setting
preserve_order=False. In both cases, the original index is preserved, so.loc-based indexing will work identically.
Returns#
- Series or DataFrame
Subset of the original grouped object as determined by n
See Also#
.head
Examples#
>>> import cudf >>> df = cudf.DataFrame( ... { ... "a": [1, 0, 1, 2, 2, 1, 3, 2, 3, 3, 3], ... "b": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ... } ... ) >>> df.groupby("a").tail(1) a b 1 0 1 5 1 5 7 2 7 10 3 10 >>> df.groupby("a").tail(-2) a b 5 1 5 7 2 7 9 3 9 10 3 10