polars.LazyFrame.tail#

LazyFrame.tail(n: int = 5) LDF[source]#

Get the last n rows.

Parameters:
n

Number of rows.

Examples

>>> df = pl.DataFrame(
...     {
...         "a": [1, 2, 3, 4, 5, 6],
...         "b": [7, 8, 9, 10, 11, 12],
...     }
... ).lazy()
>>> df.tail().collect()
shape: (5, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 2   ┆ 8   │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 3   ┆ 9   │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 4   ┆ 10  │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 5   ┆ 11  │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 6   ┆ 12  │
└─────┴─────┘
>>> df.tail(2).collect()
shape: (2, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 5   ┆ 11  │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 6   ┆ 12  │
└─────┴─────┘