Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Function

pl.max

Creates an expression that computes the maximum of each named column. It is shorthand for applying .max() to the selected columns.

How it works

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.

Syntax

polars.max(*names: str) → Expr

Parameters

NameTypeDescription
namesstrName or names of the columns to use in the aggregation.

Returns

Expr

Key points

  • Computes the maximum value for each selected column.
  • Equivalent to applying the column max expression to the supplied names.
  • The positional names specify which columns participate in the aggregation.
  • Multiple columns can be aggregated in one select operation, yielding a result for each column.
  • A regular-expression column pattern can select several matching columns.

Example: Maximum values from multiple columns

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.

When to use it

Single-column aggregation

Compute a column maximum in a DataFrame selection.

Multi-column aggregation

Calculate maxima for several columns at once.

Pattern-based selection

Aggregate columns selected by a naming pattern.

Interview questions

QWhat does pl.max return and where is it used?

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$.

QHow does pl.max handle its column arguments?

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().

QWhat is the relationship between pl.max and Expr.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.max
  • polars.max_horizontal

Source: polars.max — Polars documentation. Checked 2026-10-15.