在Python Polars中,我想知道是否可以使用.eval()
来执行元素和列之间的操作.例如,给定以下数据帧:
import polars as pl
df = pl.DataFrame({"list": [[2, 2, 2], [3, 3, 3]], "scalar": [1, 2]})
可以用scalar
列的值减go list
列中的每个元素吗?
即从这个开始
shape: (2, 2)
┌───────────┬────────┐
│ list ┆ scalar │
│ --- ┆ --- │
│ list[i64] ┆ i64 │
╞═══════════╪════════╡
│ [2, 2, 2] ┆ 1 │
│ [3, 3, 3] ┆ 2 │
└───────────┴────────┘
对此
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] │
└───────────┴────────┴───────────┘