polars.internals.series.list.ListNameSpace.eval#

ListNameSpace.eval(expr: Expr, parallel: bool = False) Series[source]#

Run any polars expression against the lists’ elements.

Parameters:
expr

Expression to run. Note that you can select an element with pl.first(), or pl.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 use in the groupby context, because we already parallel execution per group

Examples

>>> df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
>>> df.with_column(
...     pl.concat_list(["a", "b"]).arr.eval(pl.element().rank()).alias("rank")
... )
shape: (3, 3)
┌─────┬─────┬────────────┐
│ a   ┆ b   ┆ rank       │
│ --- ┆ --- ┆ ---        │
│ i64 ┆ i64 ┆ list[f32]  │
╞═════╪═════╪════════════╡
│ 1   ┆ 4   ┆ [1.0, 2.0] │
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 8   ┆ 5   ┆ [2.0, 1.0] │
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 3   ┆ 2   ┆ [2.0, 1.0] │
└─────┴─────┴────────────┘