polars.Expr.arr.eval#
- Expr.arr.eval(expr: Expr, *, as_list: bool = False) Expr[source]#
Run any polars expression against the arrays’ elements.
- Parameters:
- expr
Expression to run. Note that you can select an element with
pl.element()- as_list
Collect the resulting data as a list. This allows for expressions which output a variable amount of data.
See also
polars.Expr.arr.aggEvaluate any expression and automatically explode.
polars.Expr.list.evalSame for the List datatype.
Examples
>>> df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]}) >>> df.with_columns(rank=pl.concat_arr("a", "b").arr.eval(pl.element().rank())) shape: (3, 3) ┌─────┬─────┬───────────────┐ │ a ┆ b ┆ rank │ │ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ array[f64, 2] │ ╞═════╪═════╪═══════════════╡ │ 1 ┆ 4 ┆ [1.0, 2.0] │ │ 8 ┆ 5 ┆ [2.0, 1.0] │ │ 3 ┆ 2 ┆ [2.0, 1.0] │ └─────┴─────┴───────────────┘