pyspark.pandas.Series.between¶
-
Series.
between
(left: Any, right: Any, inclusive: Union[bool, str] = 'both') → pyspark.pandas.series.Series[source]¶ Return boolean Series equivalent to left <= series <= right. This function returns a boolean vector containing True wherever the corresponding Series element is between the boundary values left and right. NA values are treated as False.
- Parameters
- leftscalar or list-like
Left boundary.
- rightscalar or list-like
Right boundary.
- inclusive{“both”, “neither”, “left”, “right”} or boolean. “both” by default.
Include boundaries. Whether to set each bound as closed or open. Booleans are deprecated in favour of both or neither.
- Returns
- Series
Series representing whether each element is between left and right (inclusive).
Notes
This function is equivalent to
(left <= ser) & (ser <= right)
Examples
>>> s = ps.Series([2, 0, 4, 8, np.nan])
Boundary values are included by default:
>>> s.between(0, 4) 0 True 1 True 2 True 3 False 4 False dtype: bool
With inclusive set to “neither” boundary values are excluded:
>>> s.between(0, 4, inclusive="neither") 0 True 1 False 2 False 3 False 4 False dtype: bool
With inclusive set to “right” only right boundary value is included:
>>> s.between(0, 4, inclusive="right") 0 True 1 False 2 True 3 False 4 False dtype: bool
With inclusive set to “left” only left boundary value is included:
>>> s.between(0, 4, inclusive="left") 0 True 1 True 2 False 3 False 4 False dtype: bool
left and right can be any scalar value:
>>> s = ps.Series(['Alice', 'Bob', 'Carol', 'Eve']) >>> s.between('Anna', 'Daniel') 0 False 1 True 2 True 3 False dtype: bool