Код: Выделить всё
import polars as pl
df = pl.DataFrame({'class': ['a', 'a', 'b', 'b'], 'name': ['Ron', 'Jon', 'Don', 'Von'], 'score': [0.2, 0.5, 0.3, 0.4]})
df.group_by('class').agg(pl.col('score').max())
Код: Выделить всё
shape: (2, 2)
┌───────┬───────┐
│ class ┆ score │
│ --- ┆ --- │
│ str ┆ f64 │
╞═══════╪═══════╡
│ a ┆ 0.5 │
│ b ┆ 0.4 │
└───────┴───────┘
Код: Выделить всё
sdf = df.group_by('class').agg(pl.col('score').max())
sdf.join(df, on=['class', 'score'])
Код: Выделить всё
shape: (2, 3)
┌───────┬───────┬──────┐
│ class ┆ score ┆ name │
│ --- ┆ --- ┆ --- │
│ str ┆ f64 ┆ str │
╞═══════╪═══════╪══════╡
│ a ┆ 0.5 ┆ Jon │
│ b ┆ 0.4 ┆ Von │
└───────┴───────┴──────┘
Подробнее здесь: https://stackoverflow.com/questions/728 ... is-maximum
Мобильная версия