polars.Expr.list.eval#
- Expr.list.eval(expr: Expr, *, parallel: bool = False) Expr [source]#
Run any polars expression against the lists’ elements.
- Parameters:
- expr
Expression to run. Note that you can select an element with
pl.first()
, orpl.col()
- parallel
Run all expression parallel. Don’t activate this blindly. Parallelism is worth it if there is enough work to do per thread.
This likely should not be used in the group by context, because we already parallel execution per group
Examples
>>> df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]}) >>> df.with_columns( ... rank=pl.concat_list("a", "b").list.eval(pl.element().rank()) ... ) shape: (3, 3) ┌─────┬─────┬────────────┐ │ a ┆ b ┆ rank │ │ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ list[f64] │ ╞═════╪═════╪════════════╡ │ 1 ┆ 4 ┆ [1.0, 2.0] │ │ 8 ┆ 5 ┆ [2.0, 1.0] │ │ 3 ┆ 2 ┆ [2.0, 1.0] │ └─────┴─────┴────────────┘