polars.Expr.is_between#

Expr.is_between(start: Expr | datetime | date | int | float, end: Expr | datetime | date | int | float, include_bounds: bool | tuple[bool, bool] = False) Expr[source]#

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      │
└─────┴────────────┘