polars.max#

polars.max(exprs: Series) PythonLiteral | None[source]#
polars.max(exprs: IntoExpr | Iterable[IntoExpr], *more_exprs: IntoExpr) Expr

Get the maximum value.

If a single column is passed, get the maximum value of that column (vertical). If multiple columns are passed, get the maximum value of each row (horizontal).

Parameters:
exprs

Column(s) to use in the aggregation. Accepts expression input. Strings are parsed as column names, other non-expression inputs are parsed as literals.

*more_exprs

Additional columns to use in the aggregation, specified as positional arguments.

Examples

Get the maximum value by columns with a string column name.

>>> df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2], "c": ["foo", "bar", "foo"]})
>>> df.select(pl.max("a"))
shape: (1, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│ 8   │
└─────┘

Get the maximum value by row with a list of columns/expressions.

>>> df.select(pl.max(["a", "b"]))
shape: (3, 1)
┌─────┐
│ max │
│ --- │
│ i64 │
╞═════╡
│ 4   │
│ 8   │
│ 3   │
└─────┘

To aggregate maximums for more than one column/expression use pl.col(list).max() or a regular expression selector like pl.sum(regex):

>>> df.select(pl.col(["a", "b"]).max())
shape: (1, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 8   ┆ 5   │
└─────┴─────┘
>>> df.select(pl.max("^.*[ab]$"))
shape: (1, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 8   ┆ 5   │
└─────┴─────┘