Skip to content

Commit 36ac1dd

Browse files
mrw34TomAugspurger
authored andcommitted
DOC: update the Series.between docstring (#20443)
1 parent f5cfee7 commit 36ac1dd

File tree

1 file changed

+54
-5
lines changed

1 file changed

+54
-5
lines changed

pandas/core/series.py

+54-5
Original file line numberDiff line numberDiff line change
@@ -3556,19 +3556,68 @@ def isin(self, values):
35563556

35573557
def between(self, left, right, inclusive=True):
35583558
"""
3559-
Return boolean Series equivalent to left <= series <= right. NA values
3560-
will be treated as False
3559+
Return boolean Series equivalent to left <= series <= right.
3560+
3561+
This function returns a boolean vector containing `True` wherever the
3562+
corresponding Series element is between the boundary values `left` and
3563+
`right`. NA values are treated as `False`.
35613564
35623565
Parameters
35633566
----------
35643567
left : scalar
3565-
Left boundary
3568+
Left boundary.
35663569
right : scalar
3567-
Right boundary
3570+
Right boundary.
3571+
inclusive : bool, default True
3572+
Include boundaries.
35683573
35693574
Returns
35703575
-------
3571-
is_between : Series
3576+
Series
3577+
Each element will be a boolean.
3578+
3579+
Notes
3580+
-----
3581+
This function is equivalent to ``(left <= ser) & (ser <= right)``
3582+
3583+
See Also
3584+
--------
3585+
pandas.Series.gt : Greater than of series and other
3586+
pandas.Series.lt : Less than of series and other
3587+
3588+
Examples
3589+
--------
3590+
>>> s = pd.Series([2, 0, 4, 8, np.nan])
3591+
3592+
Boundary values are included by default:
3593+
3594+
>>> s.between(1, 4)
3595+
0 True
3596+
1 False
3597+
2 True
3598+
3 False
3599+
4 False
3600+
dtype: bool
3601+
3602+
With `inclusive` set to ``False`` boundary values are excluded:
3603+
3604+
>>> s.between(1, 4, inclusive=False)
3605+
0 True
3606+
1 False
3607+
2 False
3608+
3 False
3609+
4 False
3610+
dtype: bool
3611+
3612+
`left` and `right` can be any scalar value:
3613+
3614+
>>> s = pd.Series(['Alice', 'Bob', 'Carol', 'Eve'])
3615+
>>> s.between('Anna', 'Daniel')
3616+
0 False
3617+
1 True
3618+
2 True
3619+
3 False
3620+
dtype: bool
35723621
"""
35733622
if inclusive:
35743623
lmask = self >= left

0 commit comments

Comments
 (0)