Question
Polars: Replace elements in list of List column
Consider the following example series.
s = pl.Series('s', [[1, 2, 3], [3, 4, 5]])
I'd like to replace all 3s with 10s to obtain the following.
res = pl.Series('s', [[1, 2, 10], [10, 4, 5]])
Is it possible to efficiently replace elements in the lists of a List
column in polars?
Note. I've already tried converting to a dataframe and using pl.when().then()
, but pl.when()
fails for input of type List[bool]
. Moreover, I've experimented with pl.Expr.list.eval
, but couldn't get much further than the original mask.