polars.Expr.is_between

Expr.is_between(start: Union[polars.internals.expr.Expr, datetime.datetime], end: Union[polars.internals.expr.Expr, datetime.datetime], include_bounds: Union[bool, Sequence[bool]] = False) polars.internals.expr.Expr

Check if this expression is between start and end.

Parameters
start

Lower bound as primitive type or datetime.

end

Upper bound as primitive type or datetime.

include_bounds

False: Exclude both start and end (default). True: Include both start and end. [False, False]: Exclude start and exclude end. [True, True]: Include start and include end. [False, True]: Exclude start and include end. [True, False]: Include start and exclude end.

Returns
Expr that evaluates to a Boolean Series.

Examples

>>> df = pl.DataFrame(
...     {
...         "num": [1, 2, 3, 4, 5],
...     }
... )
>>> df.with_column(pl.col("num").is_between(2, 4))
shape: (5, 2)
┌─────┬────────────┐
│ num ┆ is_between │
│ --- ┆ ---        │
│ i64 ┆ bool       │
╞═════╪════════════╡
│ 1   ┆ false      │
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2   ┆ false      │
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 3   ┆ true       │
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 4   ┆ false      │
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 5   ┆ false      │
└─────┴────────────┘