Find the minimum of one column
Column aggregation
Polars · Function
Creates an expression that computes the minimum value for one or more named columns. It is shorthand for col(names).min() and can be evaluated with operations such as select.
polars.min creates an expression that computes the minimum for each selected column during an aggregation. It is shorthand for applying min to col(names), and accepts either individual column names or a pattern that selects multiple columns.
polars.min(*names: str) → Expr| Name | Type | Description |
|---|---|---|
names | str | Name(s) of the columns to use in the aggregation. |
Expr
polars.min constructs an expression for minimum-value aggregation..min() to a column expression.names parameter identifies the input columns.DataFrame.select to evaluate the expression for named columns.pl.col(name).min().import polars as pl
df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
result = df.select(pl.min("a", "b"))
print(result)Selects the minimum independently for each named column.
Column aggregation
Multi-column aggregation
Pattern-based selection
polars.min return and how is it implemented conceptually?pl.min returns a Polars expression representing a minimum aggregation. It can receive one or more column names and is syntactic sugar for pl.col(names).min().
Follow-up: How would you compute minima row by row instead of as an aggregation? Use pl.min_horizontal rather than pl.min.
polars.min to multiple columns?Pass a column name to select its minimum, or pass several names to produce one minimum result per selected column. The function can also use a column-selection pattern such as ^a|b$.
Follow-up: What does the pattern example select? It selects columns whose names match the supplied regular-expression pattern, such as a and b here.
The names argument identifies the columns used in the aggregation. The documented return type is Expr, so the expression is normally supplied to operations such as DataFrame.select.
Follow-up: What is the key distinction from min_horizontal? polars.min aggregates each selected column, whereas min_horizontal computes a row-wise minimum across columns.
polars.Expr.minpolars.min_horizontalpolars.col