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
byare ignored, and so are NaN values of a floatby. Abyof a nested dtype (List, Array, Struct and Map) compares in the ordersort()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