I am trying to achieve below polars expression :
pl.when(pl.col(a).contains("some value")).then(pl.concat_list("ArayColumn"),[A])
.when(pl.col(a).contains("some value")).then(pl.concat_list("ArayColumn"),[B])
.when(pl.col(a).contains("some value")).then(pl.concat_list("ArayColumn"),[C])
.otherwise("Z is Big").alias("Bigger Value")
But i would like to generate those expressions in-dynamic means :
exprs = []
for i,value on conditions:
exprs.append(pl.when(i).then(value))
exprs.otherwise(defaultValue).alias("Bigger Value")
i want to apply exprs on a data frame, like below:
dataFrame.with_columns(exprs).
so, i want for each row, it should first when, then, second when, then…..
i should evaluate every when.then condition and union all
my final values may contain [A, B, C].
Tried Approaches :
- For Loop and applying one by one , but if dataFrame has huge data its blasting.
- Expression chaining , but polars otherwise is taking None by default for every conditions i kept and making it slow [ few ms ]
can you suggest me any other approach ? I need to generate the expression and later i will apply on dataFrame.