Functions#

These functions are available from the polars module root and can be used as expressions, and sometimes also in eager contexts.


Available in module namespace:

all([name])

Do one of two things.

any(name)

Evaluate columnwise or elementwise with a bitwise OR operation.

apply(exprs, f[, return_dtype, returns_scalar])

Apply a custom/user-defined function (UDF) in a GroupBy context.

arange()

Create a range expression (or Series).

argsort_by(exprs[, reverse])

Find the indexes that would sort the columns.

avg()

Alias for mean.

coalesce(exprs)

Folds the expressions from left to right, keeping the first non-null value.

concat_list(exprs)

Concat the arrays in a Series dtype List in linear time.

concat_str(exprs[, sep])

Horizontally concat Utf8 Series in linear time.

count()

Count the number of values in this column/context.

cov(a, b)

Compute the covariance between two columns/ expressions.

cumfold(acc, f, exprs[, include_init])

Cumulatively accumulate over multiple columns horizontally/ row wise with a left fold.

cumreduce(f, exprs)

Cumulatively accumulate over multiple columns horizontally/ row wise with a left fold.

cumsum()

Cumulatively sum values in a column/Series, or horizontally across list of columns/expressions.

date(year, month, day)

Create polars Date from distinct time components.

datetime(year, month, day[, hour, minute, ...])

Create polars Datetime from distinct time components.

duration(*[, days, seconds, nanoseconds, ...])

Create polars Duration from distinct time components.

element()

Alias for an element in evaluated in an eval expression.

exclude(columns)

Exclude certain columns from a wildcard/regex selection.

first()

Get the first value.

fold(acc, f, exprs)

Accumulate over multiple columns horizontally/ row wise with a left fold.

format(fstring, *args)

Format expressions as a string.

groups(column)

Syntactic sugar for pl.col("foo").agg_groups().

head()

Get the first n rows.

list(name)

Aggregate to list.

lit(value[, dtype, allow_object])

Return an expression representing a literal value.

map(exprs, f[, return_dtype])

Map a custom function over multiple columns/expressions.

max()

Get the maximum value.

mean()

Get the mean value.

median()

Get the median value.

min()

Get the minimum value.

n_unique()

Count unique values.

pearson_corr(a, b[, ddof])

Compute the pearson's correlation between two columns.

quantile(column, quantile[, interpolation])

Syntactic sugar for pl.col("foo").quantile(..).

reduce(f, exprs)

Accumulate over multiple columns horizontally/ row wise with a left fold.

repeat()

Repeat a single value n times.

select(exprs)

Run polars expressions without a context.

spearman_rank_corr(a, b[, ddof, propagate_nans])

Compute the spearman rank correlation between two columns.

std()

Get the standard deviation.

struct()

Collect several columns into a Series of dtype Struct.

sum()

Sum values in a column/Series, or horizontally across list of columns/expressions.

tail()

Get the last n rows.

var()

Get the variance.

when(expr)

Start a "when, then, otherwise" expression.

Available in expression namespace:

Expr.all()

Check if all boolean values in a Boolean column are True.

Expr.any()

Check if any boolean value in a Boolean column is True.

Expr.apply(f[, return_dtype])

Apply a custom/user-defined function (UDF) in a GroupBy or Projection context.

Expr.count()

Count the number of values in this expression.

Expr.cumsum([reverse])

Get an array with the cumulative sum computed at every element.

Expr.exclude(columns)

Exclude certain columns from a wildcard/regex selection.

Expr.first()

Get the first value.

Expr.head([n])

Get the first n rows.

Expr.list()

Aggregate to list.

Expr.map(f[, return_dtype, agg_list])

Apply a custom python function to a Series or sequence of Series.

Expr.max()

Get maximum value.

Expr.mean()

Get mean value.

Expr.median()

Get median value using linear interpolation.

Expr.min()

Get minimum value.

Expr.n_unique()

Count unique values.

Expr.quantile(quantile[, interpolation])

Get quantile value.

Expr.std([ddof])

Get standard deviation.

Expr.sum()

Get sum value.

Expr.tail([n])

Get the last n rows.

Expr.var([ddof])

Get variance.