polars.Expr.list.__getitem__#

Expr.list.__getitem__(item: int) Expr[source]#

Get the value by index in the sublists.

This is syntactic sugar for Expr.list.get().

Parameters:
item

Index to return per sublist. Index 0 returns the first item, and index -1 returns the last item.

Examples

>>> df = pl.DataFrame({"a": [[3, 2, 1], [4, 5, 6]]})
>>> df.with_columns(get=pl.col("a").list[0])
shape: (2, 2)
┌───────────┬─────┐
│ a         ┆ get │
│ ---       ┆ --- │
│ list[i64] ┆ i64 │
╞═══════════╪═════╡
│ [3, 2, 1] ┆ 3   │
│ [4, 5, 6] ┆ 4   │
└───────────┴─────┘