polars.Expr.list.slice#
- Expr.list.slice( ) Expr[source]#
Slice every sub-list.
- 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
>>> df = pl.DataFrame({"a": [[1, 2, 3, 4], [10, 2, 1]]}) >>> df.with_columns(slice=pl.col("a").list.slice(1, 2)) shape: (2, 2) âââââââââââââââŦââââââââââââ â a â slice â â --- â --- â â list[i64] â list[i64] â âââââââââââââââĒâââââââââââ⥠â [1, 2, âĻ 4] â [2, 3] â â [10, 2, 1] â [2, 1] â âââââââââââââââ´ââââââââââââ