Код: Выделить всё
if x=2 then do:
x='ham'
y='eggs'
z='fruit'
end
Код: Выделить всё
df = pl.DataFrame(
{
"a": [1,2,3],
"x": ['foo','bar','baz'],
"y": ['bar','foo','baz'],
"z": ['baz','foo','bar']
}
)
df.with_columns(
pl.when(pl.col('a')==2).then(pl.lit('ham')).otherwise(pl.col('x')).alias('x'),
pl.when(pl.col('a')==2).then(pl.lit('eggs')).otherwise(pl.col('y')).alias('y'),
pl.when(pl.col('a')==2).then(pl.lit('fruit')).otherwise(pl.col('z')).alias('z'),
)
Подробнее здесь: https://stackoverflow.com/questions/771 ... -condition