Get maximum value, ordered by another expression
Description
Usage
<Expr>$max_by(by)
Arguments
by
|
Column used to determine the largest element. Accepts expression input. Strings are parsed as column names. |
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(a = c(-1, NaN, 1), b = c("x", "y", "z"))
df$with_columns(max_b_by_a = pl$col("b")$max_by("a"))
#> shape: (3, 3)
#> ┌──────┬─────┬────────────┐
#> │ a ┆ b ┆ max_b_by_a │
#> │ --- ┆ --- ┆ --- │
#> │ f64 ┆ str ┆ str │
#> ╞══════╪═════╪════════════╡
#> │ -1.0 ┆ x ┆ z │
#> │ NaN ┆ y ┆ z │
#> │ 1.0 ┆ z ┆ z │
#> └──────┴─────┴────────────┘