In python polars, I was wondering if it will be possible to use .eval()
to perform an operation between an element and a column. For example, given the following dataframe:
import polars as pl
df = pl.DataFrame({"list": [[2, 2, 2], [3, 3, 3]], "scalar": [1, 2]})
Is it possible to subtract each element of the list
column by the value of scalar
column?
i.e. from this
shape: (2, 2)
┌───────────┬────────┐
│ list ┆ scalar │
│ --- ┆ --- │
│ list[i64] ┆ i64 │
╞═══════════╪════════╡
│ [2, 2, 2] ┆ 1 │
│ [3, 3, 3] ┆ 2 │
└───────────┴────────┘
to this
shape: (2, 3)
┌───────────┬────────┬───────────┐
│ list ┆ scalar ┆ diff │
│ --- ┆ --- ┆ --- │
│ list[i64] ┆ i64 ┆ list[i64] │
╞═══════════╪════════╪═══════════╡
│ [2, 2, 2] ┆ 1 ┆ [1, 1, 1] │
│ [3, 3, 3] ┆ 2 ┆ [1, 1, 1] │
└───────────┴────────┴───────────┘