polars.internals.series.list.ListNameSpace.slice#

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