Код: Выделить всё
import polars as pl
df = pl.DataFrame({
'A' : ['foo', 'bar', 'foo', 'bar', 'foo', 'bar'],
'B' : ['one', 'one', 'two', 'three', 'two', 'two'],
'C' : [1, 5, 5, 2, 5, 7],
'D' : [2.0, 5., 8., 1., 2., 9.]
})
Код: Выделить всё
df.group_by('A').agg( pl.col('C').map_elements(lambda x: x >= x.mean()).alias('C') )
Код: Выделить всё
shape: (2, 2)
┌─────┬─────────────────────┐
│ A ┆ C │
│ --- ┆ --- │
│ str ┆ list[bool] │
╞═════╪═════════════════════╡
│ foo ┆ [false, true, true] │
│ bar ┆ [true, false, true] │
└─────┴─────────────────────┘
Подробнее здесь: https://stackoverflow.com/questions/770 ... and-python