polars.Series.is_between
-
Get a boolean mask of the values that are between the given lower/upper bounds.
- Parameters:
-
- lower_bound
-
Lower bound value. Accepts expression input. Non-expression inputs (including strings) are parsed as literals.
- upper_bound
-
Upper bound value. Accepts expression input. Non-expression inputs (including strings) are parsed as literals.
-
closed{‘both’, ‘left’, ‘right’, ‘none’} -
Define which sides of the interval are closed (inclusive).
Notes
If the value of the
lower_boundis greater than that of theupper_boundthen the result will be False, as no value can satisfy the condition.Examples
>>> s = pl.Series("num", [1, 2, 3, 4, 5]) >>> s.is_between(2, 4) shape: (5,) Series: 'num' [bool] [ false true true true false ]Use the
closedargument to include or exclude the values at the bounds:>>> s.is_between(2, 4, closed="left") shape: (5,) Series: 'num' [bool] [ false true true false false ]You can also use strings as well as numeric/temporal values:
>>> s = pl.Series("s", ["a", "b", "c", "d", "e"]) >>> s.is_between("b", "d", closed="both") shape: (5,) Series: 's' [bool] [ false true true true false ]
Series.is_between(
lower_bound: IntoExpr,
upper_bound: IntoExpr,
closed: ClosedInterval = 'both',
) → Series
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/series/api/polars.Series.is_between.html