polars.Series.list.slice#

Series.list.slice(offset: int | Expr, length: int | Expr | None = None) Series[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.list.slice(1, 2)
shape: (2,)
Series: 'a' [list[i64]]
[
    [2, 3]
    [2, 1]
]