Single-column aggregation
Compute a column maximum in a DataFrame selection.
Polars · Function
Creates an expression that computes the maximum of each named column. It is shorthand for applying .max() to the selected columns.
pl.max creates an expression that computes the maximum for each named column during a DataFrame operation. It is shorthand for selecting the columns and applying their max aggregation, and it can accept several names or a column-selection pattern.
polars.max(*names: str) → Expr| Name | Type | Description |
|---|---|---|
names | str | Name or names of the columns to use in the aggregation. |
Expr
import polars as pl
df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
result = df.select(pl.max("a", "b"))
print(result)Selects the maximum independently for columns a and b.
Compute a column maximum in a DataFrame selection.
Calculate maxima for several columns at once.
Aggregate columns selected by a naming pattern.
pl.max returns an expression that aggregates each selected column to its maximum value. It is intended for use inside operations such as DataFrame.select.
Follow-up: How can multiple columns be selected? Pass multiple names or a selector pattern such as ^a|b$.
The names argument identifies the columns whose maxima should be computed. Supplying more than one name produces one result column for each selected input column.
Follow-up: What is the concise equivalent of pl.max("a")? It is pl.col("a").max().
pl.max("a") is syntactic sugar for pl.col("a").max(). Both create an expression that computes the maximum of column a when evaluated.
Follow-up: Which related function should be considered for row-wise maxima across columns? Use max_horizontal.
polars.Expr.maxpolars.max_horizontal