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(*names[, ignore_nulls])

Either return an expression representing all columns, or evaluate a bitwise AND operation.

all_horizontal(*exprs)

Compute the bitwise AND horizontally across columns.

any(*names[, ignore_nulls])

Evaluate a bitwise OR operation.

any_horizontal(*exprs)

Compute the bitwise OR horizontally across columns.

approx_n_unique(*columns)

Approximate count of unique values.

arange([start, end, step, dtype, eager])

Generate a range of integers.

arctan2(y, x)

Compute two argument arctan in radians.

arctan2d(y, x)

Compute two argument arctan in degrees.

arg_sort_by(exprs, *more_exprs[, ...])

Return the row indices that would sort the column(s).

arg_where(condition, *[, eager])

Return indices where condition evaluates True.

business_day_count(start, end[, week_mask, ...])

Count the number of business days between start and end (not including end).

coalesce(exprs, *more_exprs)

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

concat_arr(exprs, *more_exprs)

Horizontally concatenate columns into a single array column.

concat_list(exprs, *more_exprs)

Horizontally concatenate columns into a single list column.

concat_str(exprs, *more_exprs[, separator, ...])

Horizontally concatenate columns into a single string column.

corr(a, b, *[, method, ddof, propagate_nans])

Compute the Pearson's or Spearman rank correlation correlation between two columns.

count(*columns)

Return the number of non-null values in the column.

cov(a, b[, ddof])

Compute the covariance between two columns/ expressions.

cum_count(*columns[, reverse])

Return the cumulative count of the non-null values in the column.

cum_fold(acc, function, exprs, *[, include_init])

Cumulatively fold horizontally across columns with a left fold.

cum_reduce(function, exprs)

Cumulatively reduce horizontally across columns with a left fold.

cum_sum(*names)

Cumulatively sum all values.

cum_sum_horizontal(*exprs)

Cumulatively sum all values horizontally across columns.

date(year, month, day)

Create a Polars literal expression of type Date.

date_range(start, end[, interval, closed, eager])

Generate a date range.

date_ranges(start, end[, interval, closed, ...])

Create a column of date ranges.

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

Create a Polars literal expression of type Datetime.

datetime_range(start, end[, interval, ...])

Generate a datetime range.

datetime_ranges(start, end[, interval, ...])

Create a column of datetime ranges.

duration(*[, weeks, days, hours, minutes, ...])

Create polars Duration from distinct time components.

element()

Alias for an element being evaluated in an eval expression.

exclude(columns, *more_columns)

Represent all columns except for the given columns.

first(*columns)

Get the first column or value.

fold(acc, function, exprs)

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

format(f_string, *args)

Format expressions as a string.

from_epoch(column[, time_unit])

Utility function that parses an epoch timestamp (or Unix time) to Polars Date(time).

groups(column)

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

head(column[, n])

Get the first n rows.

implode(*columns)

Aggregate all column values into a list.

int_range([start, end, step, dtype, eager])

Generate a range of integers.

int_ranges([start, end, step, dtype, eager])

Generate a range of integers for each row of the input columns.

last(*columns)

Get the last column or value.

len()

Return the number of rows in the context.

lit(value[, dtype, allow_object])

Return an expression representing a literal value.

map_batches(exprs, function[, return_dtype])

Map a custom function over multiple columns/expressions.

map_groups(exprs, function[, return_dtype, ...])

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

max(*names)

Get the maximum value.

max_horizontal(*exprs)

Get the maximum value horizontally across columns.

mean(*columns)

Get the mean value.

mean_horizontal(*exprs)

Compute the mean of all values horizontally across columns.

median(*columns)

Get the median value.

min(*names)

Get the minimum value.

min_horizontal(*exprs)

Get the minimum value horizontally across columns.

n_unique(*columns)

Count unique values.

nth(*indices)

Get the nth column(s) of the context.

ones(n[, dtype, eager])

Construct a column of length n filled with ones.

quantile(column, quantile[, interpolation])

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

reduce(function, exprs)

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

repeat(value, n, *[, dtype, eager])

Construct a column of length n filled with the given value.

rolling_corr(a, b, *, window_size[, ...])

Compute the rolling correlation between two columns/ expressions.

rolling_cov(a, b, *, window_size[, ...])

Compute the rolling covariance between two columns/ expressions.

select(*exprs, **named_exprs)

Run polars expressions without a context.

sql(query, *[, eager])

Execute a SQL query against frames in the global namespace.

sql_expr(sql)

Parse one or more SQL expressions to Polars expression(s).

std(column[, ddof])

Get the standard deviation.

struct(*exprs[, schema, eager])

Collect columns into a struct column.

sum(*names)

Sum all values.

sum_horizontal(*exprs)

Sum all values horizontally across columns.

tail(column[, n])

Get the last n rows.

time([hour, minute, second, microsecond])

Create a Polars literal expression of type Time.

time_range([start, end, interval, closed, eager])

Generate a time range.

time_ranges([start, end, interval, closed, ...])

Create a column of time ranges.

var(column[, ddof])

Get the variance.

when(*predicates, **constraints)

Start a when-then-otherwise expression.

zeros(n[, dtype, eager])

Construct a column of length n filled with zeros.

Available in expression namespace:

Expr.all(*[, ignore_nulls])

Return whether all values in the column are True.

Expr.any(*[, ignore_nulls])

Return whether any of the values in the column are True.

Expr.approx_n_unique()

Approximate count of unique values.

Expr.count()

Return the number of non-null elements in the column.

Expr.first()

Get the first value.

Expr.head([n])

Get the first n rows.

Expr.implode()

Aggregate values into a list.

Expr.map_batches(function[, return_dtype, ...])

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

Expr.map_elements(function[, return_dtype, ...])

Map a custom/user-defined function (UDF) to each element of a column.

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.