polars.Expr#

class polars.Expr[source]#

Expressions that can be used in various contexts.

Attributes:
arr

Create an object namespace of all list related methods.

cat

Create an object namespace of all categorical related methods.

dt

Create an object namespace of all datetime related methods.

meta

Create an object namespace of all meta related expression methods.

str

Create an object namespace of all string related methods.

struct

Create an object namespace of all struct related methods.

Methods

abs()

Compute absolute values.

agg_groups()

Get the group indexes of the group by operation.

alias(name)

Rename the output of an expression.

all()

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

any()

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

append(other[, upcast])

Append expressions.

apply(f[, return_dtype])

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

arccos()

Compute the element-wise value for the inverse cosine.

arccosh()

Compute the element-wise value for the inverse hyperbolic cosine.

arcsin()

Compute the element-wise value for the inverse sine.

arcsinh()

Compute the element-wise value for the inverse hyperbolic sine.

arctan()

Compute the element-wise value for the inverse tangent.

arctanh()

Compute the element-wise value for the inverse hyperbolic tangent.

arg_max()

Get the index of the maximal value.

arg_min()

Get the index of the minimal value.

arg_sort([reverse, nulls_last])

Get the index values that would sort this column.

arg_unique()

Get index of first unique value.

argsort([reverse, nulls_last])

Get the index values that would sort this column.

backward_fill([limit])

Fill missing values with the next to be seen values.

cast(dtype[, strict])

Cast between data types.

ceil()

Rounds up to the nearest integer value.

clip(min_val, max_val)

Clip (limit) the values in an array to a min and max boundary.

clip_max(max_val)

Clip (limit) the values in an array to a max boundary.

clip_min(min_val)

Clip (limit) the values in an array to a min boundary.

cos()

Compute the element-wise value for the cosine.

cosh()

Compute the element-wise value for the hyperbolic cosine.

count()

Count the number of values in this expression.

cumcount([reverse])

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

cummax([reverse])

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

cummin([reverse])

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

cumprod([reverse])

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

cumsum([reverse])

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

cumulative_eval(expr[, min_periods, parallel])

Run an expression over a sliding window that increases 1 slot every iteration.

diff([n, null_behavior])

Calculate the n-th discrete difference.

dot(other)

Compute the dot/inner product between two Expressions.

drop_nans()

Drop floating point NaN values.

drop_nulls()

Drop null values.

entropy([base, normalize])

Computes the entropy.

ewm_mean([com, span, half_life, alpha, ...])

Exponentially-weighted moving average.

ewm_std([com, span, half_life, alpha, ...])

Exponentially-weighted moving standard deviation.

ewm_var([com, span, half_life, alpha, ...])

Exponentially-weighted moving variance.

exclude(columns)

Exclude certain columns from a wildcard/regex selection.

exp()

Compute the exponential, element-wise.

explode()

Explode a list or utf8 Series.

extend_constant(value, n)

Extend the Series with given number of values.

fill_nan(fill_value)

Fill floating point NaN value with a fill value.

fill_null([value, strategy, limit])

Fill null values using the specified value or strategy.

filter(predicate)

Filter a single column.

first()

Get the first value.

flatten()

Alias for explode().

floor()

Rounds down to the nearest integer value.

forward_fill([limit])

Fill missing values with the latest seen values.

hash([seed, seed_1, seed_2, seed_3])

Hash the elements in the selection.

head([n])

Get the first n rows.

inspect([fmt])

Print the value that this expression evaluates to and pass on the value.

interpolate()

Fill nulls with linear interpolation over missing values.

is_between(start, end[, include_bounds])

Check if this expression is between start and end.

is_duplicated()

Get mask of duplicated values.

is_finite()

Returns a boolean Series indicating which values are finite.

is_first()

Get a mask of the first unique value.

is_in(other)

Check if elements of this expression are present in the other Series.

is_infinite()

Returns a boolean Series indicating which values are infinite.

is_nan()

Returns a boolean Series indicating which values are NaN.

is_not()

Negate a boolean expression.

is_not_nan()

Returns a boolean Series indicating which values are not NaN.

is_not_null()

Returns a boolean Series indicating which values are not null.

is_null()

Returns a boolean Series indicating which values are null.

is_unique()

Get mask of unique values.

keep_name()

Keep the original root name of the expression.

kurtosis([fisher, bias])

Compute the kurtosis (Fisher or Pearson) of a dataset.

last()

Get the last value.

len()

Count the number of values in this expression.

limit([n])

Get the first n rows.

list()

Aggregate to list.

log([base])

Compute the logarithm to a given base.

log10()

Compute the base 10 logarithm of the input array, element-wise.

lower_bound()

Calculate the lower bound.

map(f[, return_dtype, agg_list])

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

map_alias(f)

Rename the output of an expression by mapping a function over the root name.

max()

Get maximum value.

mean()

Get mean value.

median()

Get median value using linear interpolation.

min()

Get minimum value.

mode()

Compute the most occurring value(s).

n_unique()

Count unique values.

nan_max()

Get maximum value, but propagate/poison encountered NaN values.

nan_min()

Get minimum value, but propagate/poison encountered NaN values.

null_count()

Count null values.

over(expr)

Apply window function over a subgroup.

pct_change([n])

Computes percentage change between values.

pow(exponent)

Raise expression to the power of exponent.

prefix(prefix)

Add a prefix to the root column name of the expression.

product()

Compute the product of an expression.

quantile(quantile[, interpolation])

Get quantile value.

rank([method, reverse])

Assign ranks to data, dealing with ties appropriately.

rechunk()

Create a single chunk of memory for this Series.

reinterpret([signed])

Reinterpret the underlying bits as a signed/unsigned integer.

repeat_by(by)

Repeat the elements in this Series as specified in the given expression.

reshape(dims)

Reshape this Expr to a flat Series or a Series of Lists.

reverse()

Reverse the selection.

rolling_apply(function, window_size[, ...])

Apply a custom rolling window function.

rolling_max(window_size[, weights, ...])

Apply a rolling max (moving max) over the values in this array.

rolling_mean(window_size[, weights, ...])

Apply a rolling mean (moving mean) over the values in this array.

rolling_median(window_size[, weights, ...])

Compute a rolling median.

rolling_min(window_size[, weights, ...])

Apply a rolling min (moving min) over the values in this array.

rolling_quantile(quantile[, interpolation, ...])

Compute a rolling quantile.

rolling_skew(window_size[, bias])

Compute a rolling skew.

rolling_std(window_size[, weights, ...])

Compute a rolling standard deviation.

rolling_sum(window_size[, weights, ...])

Apply a rolling sum (moving sum) over the values in this array.

rolling_var(window_size[, weights, ...])

Compute a rolling variance.

round(decimals)

Round underlying floating point data by decimals digits.

sample([frac, with_replacement, shuffle, ...])

Sample from this expression.

search_sorted(element)

Find indices where elements should be inserted to maintain order.

set_sorted([reverse])

Flags the expression as 'sorted'.

shift([periods])

Shift the values by a given period.

shift_and_fill(periods, fill_value)

Shift the values by a given period and fill the resulting null values.

shuffle([seed])

Shuffle the contents of this expr.

sign()

Compute the element-wise indication of the sign.

sin()

Compute the element-wise value for the sine.

sinh()

Compute the element-wise value for the hyperbolic sine.

skew([bias])

Compute the sample skewness of a data set.

slice(offset[, length])

Get a slice of this expression.

sort([reverse, nulls_last])

Sort this column.

sort_by(by[, reverse])

Sort this column by the ordering of another column, or multiple other columns.

sqrt()

Compute the square root of the elements.

std([ddof])

Get standard deviation.

suffix(suffix)

Add a suffix to the root column name of the expression.

sum()

Get sum value.

tail([n])

Get the last n rows.

take(indices)

Take values by index.

take_every(n)

Take every nth value in the Series and return as a new Series.

tan()

Compute the element-wise value for the tangent.

tanh()

Compute the element-wise value for the hyperbolic tangent.

to_physical()

Cast to physical representation of the logical dtype.

top_k([k, reverse])

Return the k largest elements.

unique([maintain_order])

Get unique values of this expression.

unique_counts()

Return a count of the unique values in the order of appearance.

upper_bound()

Calculate the upper bound.

value_counts([multithreaded, sort])

Count all unique values and create a struct mapping value to count.

var([ddof])

Get variance.

where(predicate)

Filter a single column.

__init__(*args, **kwargs)#

Methods

__init__(*args, **kwargs)

abs()

Compute absolute values.

agg_groups()

Get the group indexes of the group by operation.

alias(name)

Rename the output of an expression.

all()

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

any()

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

append(other[, upcast])

Append expressions.

apply(f[, return_dtype])

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

arccos()

Compute the element-wise value for the inverse cosine.

arccosh()

Compute the element-wise value for the inverse hyperbolic cosine.

arcsin()

Compute the element-wise value for the inverse sine.

arcsinh()

Compute the element-wise value for the inverse hyperbolic sine.

arctan()

Compute the element-wise value for the inverse tangent.

arctanh()

Compute the element-wise value for the inverse hyperbolic tangent.

arg_max()

Get the index of the maximal value.

arg_min()

Get the index of the minimal value.

arg_sort([reverse, nulls_last])

Get the index values that would sort this column.

arg_unique()

Get index of first unique value.

argsort([reverse, nulls_last])

Get the index values that would sort this column.

backward_fill([limit])

Fill missing values with the next to be seen values.

cast(dtype[, strict])

Cast between data types.

ceil()

Rounds up to the nearest integer value.

clip(min_val, max_val)

Clip (limit) the values in an array to a min and max boundary.

clip_max(max_val)

Clip (limit) the values in an array to a max boundary.

clip_min(min_val)

Clip (limit) the values in an array to a min boundary.

cos()

Compute the element-wise value for the cosine.

cosh()

Compute the element-wise value for the hyperbolic cosine.

count()

Count the number of values in this expression.

cumcount([reverse])

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

cummax([reverse])

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

cummin([reverse])

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

cumprod([reverse])

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

cumsum([reverse])

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

cumulative_eval(expr[, min_periods, parallel])

Run an expression over a sliding window that increases 1 slot every iteration.

diff([n, null_behavior])

Calculate the n-th discrete difference.

dot(other)

Compute the dot/inner product between two Expressions.

drop_nans()

Drop floating point NaN values.

drop_nulls()

Drop null values.

entropy([base, normalize])

Computes the entropy.

ewm_mean([com, span, half_life, alpha, ...])

Exponentially-weighted moving average.

ewm_std([com, span, half_life, alpha, ...])

Exponentially-weighted moving standard deviation.

ewm_var([com, span, half_life, alpha, ...])

Exponentially-weighted moving variance.

exclude(columns)

Exclude certain columns from a wildcard/regex selection.

exp()

Compute the exponential, element-wise.

explode()

Explode a list or utf8 Series.

extend_constant(value, n)

Extend the Series with given number of values.

fill_nan(fill_value)

Fill floating point NaN value with a fill value.

fill_null([value, strategy, limit])

Fill null values using the specified value or strategy.

filter(predicate)

Filter a single column.

first()

Get the first value.

flatten()

Alias for explode().

floor()

Rounds down to the nearest integer value.

forward_fill([limit])

Fill missing values with the latest seen values.

hash([seed, seed_1, seed_2, seed_3])

Hash the elements in the selection.

head([n])

Get the first n rows.

inspect([fmt])

Print the value that this expression evaluates to and pass on the value.

interpolate()

Fill nulls with linear interpolation over missing values.

is_between(start, end[, include_bounds])

Check if this expression is between start and end.

is_duplicated()

Get mask of duplicated values.

is_finite()

Returns a boolean Series indicating which values are finite.

is_first()

Get a mask of the first unique value.

is_in(other)

Check if elements of this expression are present in the other Series.

is_infinite()

Returns a boolean Series indicating which values are infinite.

is_nan()

Returns a boolean Series indicating which values are NaN.

is_not()

Negate a boolean expression.

is_not_nan()

Returns a boolean Series indicating which values are not NaN.

is_not_null()

Returns a boolean Series indicating which values are not null.

is_null()

Returns a boolean Series indicating which values are null.

is_unique()

Get mask of unique values.

keep_name()

Keep the original root name of the expression.

kurtosis([fisher, bias])

Compute the kurtosis (Fisher or Pearson) of a dataset.

last()

Get the last value.

len()

Count the number of values in this expression.

limit([n])

Get the first n rows.

list()

Aggregate to list.

log([base])

Compute the logarithm to a given base.

log10()

Compute the base 10 logarithm of the input array, element-wise.

lower_bound()

Calculate the lower bound.

map(f[, return_dtype, agg_list])

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

map_alias(f)

Rename the output of an expression by mapping a function over the root name.

max()

Get maximum value.

mean()

Get mean value.

median()

Get median value using linear interpolation.

min()

Get minimum value.

mode()

Compute the most occurring value(s).

n_unique()

Count unique values.

nan_max()

Get maximum value, but propagate/poison encountered NaN values.

nan_min()

Get minimum value, but propagate/poison encountered NaN values.

null_count()

Count null values.

over(expr)

Apply window function over a subgroup.

pct_change([n])

Computes percentage change between values.

pow(exponent)

Raise expression to the power of exponent.

prefix(prefix)

Add a prefix to the root column name of the expression.

product()

Compute the product of an expression.

quantile(quantile[, interpolation])

Get quantile value.

rank([method, reverse])

Assign ranks to data, dealing with ties appropriately.

rechunk()

Create a single chunk of memory for this Series.

reinterpret([signed])

Reinterpret the underlying bits as a signed/unsigned integer.

repeat_by(by)

Repeat the elements in this Series as specified in the given expression.

reshape(dims)

Reshape this Expr to a flat Series or a Series of Lists.

reverse()

Reverse the selection.

rolling_apply(function, window_size[, ...])

Apply a custom rolling window function.

rolling_max(window_size[, weights, ...])

Apply a rolling max (moving max) over the values in this array.

rolling_mean(window_size[, weights, ...])

Apply a rolling mean (moving mean) over the values in this array.

rolling_median(window_size[, weights, ...])

Compute a rolling median.

rolling_min(window_size[, weights, ...])

Apply a rolling min (moving min) over the values in this array.

rolling_quantile(quantile[, interpolation, ...])

Compute a rolling quantile.

rolling_skew(window_size[, bias])

Compute a rolling skew.

rolling_std(window_size[, weights, ...])

Compute a rolling standard deviation.

rolling_sum(window_size[, weights, ...])

Apply a rolling sum (moving sum) over the values in this array.

rolling_var(window_size[, weights, ...])

Compute a rolling variance.

round(decimals)

Round underlying floating point data by decimals digits.

sample([frac, with_replacement, shuffle, ...])

Sample from this expression.

search_sorted(element)

Find indices where elements should be inserted to maintain order.

set_sorted([reverse])

Flags the expression as 'sorted'.

shift([periods])

Shift the values by a given period.

shift_and_fill(periods, fill_value)

Shift the values by a given period and fill the resulting null values.

shuffle([seed])

Shuffle the contents of this expr.

sign()

Compute the element-wise indication of the sign.

sin()

Compute the element-wise value for the sine.

sinh()

Compute the element-wise value for the hyperbolic sine.

skew([bias])

Compute the sample skewness of a data set.

slice(offset[, length])

Get a slice of this expression.

sort([reverse, nulls_last])

Sort this column.

sort_by(by[, reverse])

Sort this column by the ordering of another column, or multiple other columns.

sqrt()

Compute the square root of the elements.

std([ddof])

Get standard deviation.

suffix(suffix)

Add a suffix to the root column name of the expression.

sum()

Get sum value.

tail([n])

Get the last n rows.

take(indices)

Take values by index.

take_every(n)

Take every nth value in the Series and return as a new Series.

tan()

Compute the element-wise value for the tangent.

tanh()

Compute the element-wise value for the hyperbolic tangent.

to_physical()

Cast to physical representation of the logical dtype.

top_k([k, reverse])

Return the k largest elements.

unique([maintain_order])

Get unique values of this expression.

unique_counts()

Return a count of the unique values in the order of appearance.

upper_bound()

Calculate the upper bound.

value_counts([multithreaded, sort])

Count all unique values and create a struct mapping value to count.

var([ddof])

Get variance.

where(predicate)

Filter a single column.

Attributes

arr

Create an object namespace of all list related methods.

cat

Create an object namespace of all categorical related methods.

dt

Create an object namespace of all datetime related methods.

meta

Create an object namespace of all meta related expression methods.

str

Create an object namespace of all string related methods.

struct

Create an object namespace of all struct related methods.