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

Polars · Function

pl.mean

polars.mean creates an expression that computes the mean of one or more named columns. It is shorthand for pl.col(columns).mean().

How it works

pl.mean builds an expression that computes the average for each named column when evaluated in a DataFrame operation. It is shorthand for applying mean to pl.col with the supplied column names, and multiple names produce multiple output columns.

Syntax

polars.mean(*columns: str) → Expr

Parameters

NameTypeDescription
columnsstrOne or more column names.

Returns

Expr

Key points

  • Computes the arithmetic mean for the specified column expressions.
  • It is a convenience wrapper around a column expression followed by the expression-level mean operation.
  • The columns argument accepts one or more names, allowing a single call to target several columns.
  • The function returns an Expr, so it is intended for use inside DataFrame or lazy query expressions.

Example: Mean of multiple columns

import polars as pl

df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
result = df.select(pl.mean("a", "b"))
print(result)

Selects the mean of each named column, producing one result column per input column.

When to use it

Column summaries

Summarise selected numeric columns in an eager DataFrame.

Lazy expression pipelines

Build reusable aggregations in a lazy query.

Multi-column aggregation

Compute several column means in one select operation.

Interview questions

QWhat does pl.mean return and when is it evaluated?

It returns a Polars expression that computes the mean value for the specified columns. The expression is evaluated when used in an operation such as select.

Follow-up: How can the same operation be written without the convenience function? Use pl.col("a").mean() for one column, or apply the column expression to each desired column.

QHow do you compute means for multiple columns?

Pass one or more column names to pl.mean. Each selected column gets its own mean result, so pl.mean("a", "b") yields two output columns.

Follow-up: What does the convenience function expand to? It is syntactic sugar for pl.col(columns).mean().

QWhat are the parameter and return types?

The documented parameter is columns, representing one or more column names. The function returns an Expr, which can be composed into a larger Polars query.

Follow-up: How would you compute a row-wise mean instead? Use the separately documented horizontal mean functionality rather than this column-wise expression.

  • polars.Expr.mean
  • polars.mean_horizontal

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