polars.Expr.arr.slice#

Expr.arr.slice(offset: int | str | Expr, length: int | str | Expr | None = None) Expr[source]#

Slice every sublist.

Parameters:
offset

Start index. Negative indexing is supported.

length

Length of the slice. If set to None (default), the slice is taken to the end of the list.

Examples

>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.slice(1, 2)
shape: (2,)
Series: 'a' [list]
[
    [2, 3]
    [2, 1]
]