The Series.between()
function is used to obtain the boolean Series containing True
for the elements that fall between the boundaries provided and False
otherwise.
Series.between(self, left, right, inclusive=True)
left
: This represents left boundaries. It is mandatory
right
: This represents the right boundaries. It is mandatory
inclusive
: This parameter is used to include the boundaries. it could be both
, neither
, left
, right
boundaries. This parameter is mandatory.
import pandas as pdimport numpy as np# create Seriesnum_series = pd.Series([np.nan, 1, 0, 9, 7, 4,np.nan, 2])# using Series.between()print(num_series.between(1,3))
Line 1–2: We import the libraries, pandas
and numpy
.
Line 4: We create num_series
of length 8
.
Lines 7: We return a boolean Series representing elements between left (1
) and right(3
) using the between()
function.
Note: The left (
1
) and right(3
) are inclusive.