polars.Expr.min_by#

Expr.min_by(by: IntoExpr) Expr[source]#

Get minimum value, ordered by another expression.

If the by expression has multiple values equal to the minimum it is not defined which value will be chosen.

engine:In MemoryStreaming

Warning

This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.

Parameters:
by

Column used to determine the smallest element. Accepts expression input. Strings are parsed as column names.

Examples

>>> df = pl.DataFrame({"a": [-1.0, float("nan"), 1.0], "b": ["x", "y", "z"]})
>>> df.select(pl.col("b").min_by("a"))
shape: (1, 1)
┌─────┐
│ b   │
│ --- │
│ str │
╞═════╡
│ x   │
└─────┘