When evaluating list elements I would like to know and use the current index. Is there already a way of doing it?
Something like pl.element().idx()
?
import polars as pl
data = {"a": [[1,2,3],[4,5,6]]}
schema = {"a": pl.List(pl.Int8)}
df = pl.DataFrame(data, schema=schema).with_columns([
pl.col("a").list.eval(pl.element() * pl.element().idx() )
])
Expected result:
+-------------+
¦ a ¦
¦ --- ¦
¦ list[u8] ¦
¦-------------¦
¦ [0, 2, 6] ¦
¦ [0, 5, 12] ¦
+-------------+