polars.Expr.take

Expr.take(index: Union[List[int], polars.internals.expr.Expr, polars.internals.series.Series, numpy.ndarray]) polars.internals.expr.Expr

Take values by index.

Parameters
index

An expression that leads to a UInt32 dtyped Series.

Returns
Values taken by index

Examples

>>> df = pl.DataFrame(
...     {
...         "group": [
...             "one",
...             "one",
...             "one",
...             "two",
...             "two",
...             "two",
...         ],
...         "value": [1, 98, 2, 3, 99, 4],
...     }
... )
>>> df.groupby("group").agg(pl.col("value").take(1))
shape: (2, 2)
┌───────┬───────┐
│ group ┆ value │
│ ---   ┆ ---   │
│ str   ┆ i64   │
╞═══════╪═══════╡
│ one   ┆ 98    │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ two   ┆ 99    │
└───────┴───────┘