polars.Expr

class polars.Expr

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.

str

Create an object namespace of all string related methods.

struct

Create an object namespace of all struct related methods.

Methods

abs()

Take 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 the column are True

any()

Check if any boolean value in the column is True

apply(f[, return_dtype])

Apply a custom function in a GroupBy or Projection context.

arccos()

Compute the element-wise value for Trigonometric cosine on an array

arcsin()

Compute the element-wise value for Trigonometric sine on an array

arctan()

Compute the element-wise value for Trigonometric tangent on an array

arg_max()

Get the index of the maximal value.

arg_min()

Get the index of the minimal value.

arg_sort([reverse])

Get the index values that would sort this column.

arg_unique()

Get index of first unique value.

argsort([reverse])

alias for arg_sort

backward_fill()

Fill missing values with the next to be seen values

cast(dtype[, strict])

Cast between data types.

ceil()

Ceil underlying floating point array to the highest integers smaller or equal to the float value.

clip(min_val, max_val)

Clip (limit) the values in an array to any value that fits in 64 floating poitns range.

cos()

Compute the element-wise value for Trigonometric cosine on an array

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])

Compute the entropy as -sum(pk * log(pk).

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

Exponential moving average.

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

Exponential moving standard deviation.

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

Exponential moving standard deviation.

exclude(columns)

Exclude certain columns from a wildcard/regex selection.

exp()

Return 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(fill_value)

Fill null values using a filling strategy, literal, or Expr.

filter(predicate)

Filter a single column.

first()

Get the first value.

flatten()

Alias for explode.

floor()

Floor underlying floating point array to the lowest integers smaller or equal to the float value.

forward_fill()

Fill missing values with the latest seen values

hash([seed])

Hash the Series.

head([n])

Take the first n values.

inspect([fmt])

Prints the value that this expression evaluates to and passes on the value.

interpolate()

Interpolate intermediate 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()

Create a boolean expression returning True where the expression values are finite.

is_first()

Get a mask of the first unique value.

is_in(other)

Check if elements of this Series are in the right Series, or List values of the right Series.

is_infinite()

Create a boolean expression returning True where the expression values are infinite.

is_nan()

Create a boolean expression returning True where the expression values are NaN (Not A Number).

is_not()

Negate a boolean expression.

is_not_nan()

Create a boolean expression returning True where the expression values are not NaN (Not A Number).

is_not_null()

Create a boolean expression returning True where the expression does not contain null values.

is_null()

Create a boolean expression returning True where the expression contains null values.

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()

Alias for count Count the number of values in this expression

list()

Aggregate to list.

log([base])

Compute the logarithm to a given base

log10()

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

lower_bound()

Returns a unit Series with the lowest value possible for the dtype of this expression.

map(f[, return_dtype, agg_list])

Apply a custom python function.

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.

null_count()

Count unique values.

over(expr)

Apply window function over a subgroup.

pct_change([n])

Percentage change (as fraction) between current element and most-recent non-null element at least n period(s) before the current element.

pow(exponent)

Raise expression to the power of exponent.

prefix(prefix)

Add a prefix the to 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.

reinterpret(signed)

Reinterpret the underlying bits as a signed/unsigned integer.

repeat_by(by)

Repeat the elements in this Series n times by dictated by the number given by by.

reshape(dims)

Reshape this Expr to a flat series, shape: (len,) or a List series, shape: (rows, cols)

reverse()

Reverse the selection.

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

Allows 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 std dev

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([fraction, with_replacement, ...])

Sample a fraction of the Series.

shift([periods])

Shift the values by a given period and fill the parts that will be empty due to this operation with nulls.

shift_and_fill(periods, fill_value)

Shift the values by a given period and fill the parts that will be empty due to this operation with the result of the fill_value expression.

shuffle([seed])

Shuffle the contents of this expr.

sign()

Returns an element-wise indication of the sign of a number.

sin()

Compute the element-wise value for Trigonometric sine on an array

skew([bias])

Compute the sample skewness of a data set.

slice(offset, length)

Slice the Series.

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()

Get standard deviation.

suffix(suffix)

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

sum()

Get sum value.

tail([n])

Take the last n values.

take(index)

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 Trigonometric tangent on an array

to_physical()

Cast to physical representation of the logical dtype.

unique([maintain_order])

Get unique values of this expression.

unique_counts()

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

upper_bound()

Returns a unit Series with the highest value possible for the dtype of this expression.

value_counts([multithreaded])

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

var()

Get variance.

where(predicate)

Alias for filter

eq

gt

gt_eq

lt

lt_eq

neq

__init__() None

Methods

__init__()

abs()

Take 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 the column are True

any()

Check if any boolean value in the column is True

apply(f[, return_dtype])

Apply a custom function in a GroupBy or Projection context.

arccos()

Compute the element-wise value for Trigonometric cosine on an array

arcsin()

Compute the element-wise value for Trigonometric sine on an array

arctan()

Compute the element-wise value for Trigonometric tangent on an array

arg_max()

Get the index of the maximal value.

arg_min()

Get the index of the minimal value.

arg_sort([reverse])

Get the index values that would sort this column.

arg_unique()

Get index of first unique value.

argsort([reverse])

alias for arg_sort

backward_fill()

Fill missing values with the next to be seen values

cast(dtype[, strict])

Cast between data types.

ceil()

Ceil underlying floating point array to the highest integers smaller or equal to the float value.

clip(min_val, max_val)

Clip (limit) the values in an array to any value that fits in 64 floating poitns range.

cos()

Compute the element-wise value for Trigonometric cosine on an array

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])

Compute the entropy as -sum(pk * log(pk).

eq(other)

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

Exponential moving average.

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

Exponential moving standard deviation.

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

Exponential moving standard deviation.

exclude(columns)

Exclude certain columns from a wildcard/regex selection.

exp()

Return 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(fill_value)

Fill null values using a filling strategy, literal, or Expr.

filter(predicate)

Filter a single column.

first()

Get the first value.

flatten()

Alias for explode.

floor()

Floor underlying floating point array to the lowest integers smaller or equal to the float value.

forward_fill()

Fill missing values with the latest seen values

gt(other)

gt_eq(other)

hash([seed])

Hash the Series.

head([n])

Take the first n values.

inspect([fmt])

Prints the value that this expression evaluates to and passes on the value.

interpolate()

Interpolate intermediate 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()

Create a boolean expression returning True where the expression values are finite.

is_first()

Get a mask of the first unique value.

is_in(other)

Check if elements of this Series are in the right Series, or List values of the right Series.

is_infinite()

Create a boolean expression returning True where the expression values are infinite.

is_nan()

Create a boolean expression returning True where the expression values are NaN (Not A Number).

is_not()

Negate a boolean expression.

is_not_nan()

Create a boolean expression returning True where the expression values are not NaN (Not A Number).

is_not_null()

Create a boolean expression returning True where the expression does not contain null values.

is_null()

Create a boolean expression returning True where the expression contains null values.

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()

Alias for count Count the number of values in this expression

list()

Aggregate to list.

log([base])

Compute the logarithm to a given base

log10()

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

lower_bound()

Returns a unit Series with the lowest value possible for the dtype of this expression.

lt(other)

lt_eq(other)

map(f[, return_dtype, agg_list])

Apply a custom python function.

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.

neq(other)

null_count()

Count unique values.

over(expr)

Apply window function over a subgroup.

pct_change([n])

Percentage change (as fraction) between current element and most-recent non-null element at least n period(s) before the current element.

pow(exponent)

Raise expression to the power of exponent.

prefix(prefix)

Add a prefix the to 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.

reinterpret(signed)

Reinterpret the underlying bits as a signed/unsigned integer.

repeat_by(by)

Repeat the elements in this Series n times by dictated by the number given by by.

reshape(dims)

Reshape this Expr to a flat series, shape: (len,) or a List series, shape: (rows, cols)

reverse()

Reverse the selection.

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

Allows 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 std dev

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([fraction, with_replacement, ...])

Sample a fraction of the Series.

shift([periods])

Shift the values by a given period and fill the parts that will be empty due to this operation with nulls.

shift_and_fill(periods, fill_value)

Shift the values by a given period and fill the parts that will be empty due to this operation with the result of the fill_value expression.

shuffle([seed])

Shuffle the contents of this expr.

sign()

Returns an element-wise indication of the sign of a number.

sin()

Compute the element-wise value for Trigonometric sine on an array

skew([bias])

Compute the sample skewness of a data set.

slice(offset, length)

Slice the Series.

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()

Get standard deviation.

suffix(suffix)

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

sum()

Get sum value.

tail([n])

Take the last n values.

take(index)

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 Trigonometric tangent on an array

to_physical()

Cast to physical representation of the logical dtype.

unique([maintain_order])

Get unique values of this expression.

unique_counts()

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

upper_bound()

Returns a unit Series with the highest value possible for the dtype of this expression.

value_counts([multithreaded])

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

var()

Get variance.

where(predicate)

Alias for filter

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.

str

Create an object namespace of all string related methods.

struct

Create an object namespace of all struct related methods.