Skip to main content
`Ctrl`+`K`

# pandas.api.typing.SeriesGroupBy.tail

SeriesGroupBy.tail(n=5)

  Return last n rows of each group.

  Similar to `.apply(lambda x: x.tail(n))`, but it returns a subset of rows from the original DataFrame with original index and order preserved (`as_index` flag is ignored).

  Parameters:
    n int

      If positive: number of entries to include from end of each group. If negative: number of entries to exclude from start of each group.

  Returns:
    Series or DataFrame

      Subset of original Series or DataFrame as determined by n.

  See also

  `Series.tail`

    Apply function tail to a Series.

  `DataFrame.tail`

    Apply function tail to each row or column of a DataFrame.

  Examples

      >>> df = pd.DataFrame(
      ...     [["a", 1], ["a", 2], ["b", 1], ["b", 2]], columns=["A", "B"]
      ... )
      >>> df.groupby("A").tail(1)
         A  B
      1  a  2
      3  b  2
      >>> df.groupby("A").tail(-1)
         A  B
      1  a  2
      3  b  2