Skip to content

Get minimum value, ordered by another expression

Source code

Description

[Experimental]

Usage

<Expr>$min_by(by)

Arguments

by Column used to determine the smallest 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(min_b_by_a = pl$col("b")$min_by("a"))
#> shape: (3, 3)
#> ┌──────┬─────┬────────────┐
#> │ a    ┆ b   ┆ min_b_by_a │
#> │ ---  ┆ --- ┆ ---        │
#> │ f64  ┆ str ┆ str        │
#> ╞══════╪═════╪════════════╡
#> │ -1.0 ┆ x   ┆ x          │
#> │ NaN  ┆ y   ┆ x          │
#> │ 1.0  ┆ z   ┆ x          │
#> └──────┴─────┴────────────┘