I'd like to create a conditional incremented column in polars.
It should start from 1 and increment only if a certain condition (pl.col('code') == 'L') is met.
import polars as pl
df = pl.DataFrame({'file': ['a.txt','a.txt','a.txt','a.txt','b.txt','b.txt','c.txt','c.txt','c.txt','c.txt','c.txt'],
'code': ['X','Y','Z','L','A','A','B','L','C','L','X']
})
df.with_columns(pl.int_range(start=1, end=pl.len()+1).over('file').alias('rrr')
)
这会产生一个简单的无条件增量.但我如何添加条件呢?