polars.Series.max_by#

Series.max_by(by: IntoExpr) → Expr[source]#

Get the maximum value in this Series, ordered by an expression.

Null values of by are ignored, and so are NaN values of a float by. A by of a nested dtype (List, Array, Struct and Map) compares in the order sort() puts it in, where NaN is larger than any other number.

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

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 largest element. Accepts expression input. Strings are parsed as column names.

Examples

>>> s = pl.Series("a", [-2.0, float("nan"), 1.0])
>>> s.max_by(pl.col.a.abs())
-2.0