Skip to content

Commit f09c3c9

Browse files
committed
DOC: update the Series.between docstring
1 parent 01882ba commit f09c3c9

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

pandas/core/series.py

+49-4
Original file line numberDiff line numberDiff line change
@@ -3511,19 +3511,64 @@ def isin(self, values):
35113511

35123512
def between(self, left, right, inclusive=True):
35133513
"""
3514-
Return boolean Series equivalent to left <= series <= right. NA values
3515-
will be treated as False
3514+
Return boolean Series equivalent to left <= series <= right.
3515+
3516+
This function returns a boolean vector containing `True` wherever the
3517+
corresponding Series element is between the boundary values `left` and
3518+
`right`. NA values are treated as `False`.
35163519
35173520
Parameters
35183521
----------
35193522
left : scalar
3520-
Left boundary
3523+
Left boundary.
35213524
right : scalar
3522-
Right boundary
3525+
Right boundary.
3526+
inclusive : bool, default True
3527+
Include boundaries.
35233528
35243529
Returns
35253530
-------
35263531
is_between : Series
3532+
3533+
Examples
3534+
--------
3535+
3536+
>>> s = pd.Series([2, 0, 4, 8, np.nan])
3537+
3538+
Boundary values are included by default:
3539+
3540+
>>> s.between(1, 4)
3541+
0 True
3542+
1 False
3543+
2 True
3544+
3 False
3545+
4 False
3546+
dtype: bool
3547+
3548+
With `inclusive` set to `False` boundary values are excluded:
3549+
3550+
>>> s.between(1, 4, inclusive=False)
3551+
0 True
3552+
1 False
3553+
2 False
3554+
3 False
3555+
4 False
3556+
dtype: bool
3557+
3558+
`left` and `right` can be any scalar value:
3559+
3560+
>>> s = pd.Series(['Alice', 'Bob', 'Carol', 'Eve'])
3561+
>>> s.between('Anna', 'Daniel')
3562+
0 False
3563+
1 True
3564+
2 True
3565+
3 False
3566+
dtype: bool
3567+
3568+
See Also
3569+
--------
3570+
DataFrame.query : Query the columns of a frame with a boolean
3571+
expression.
35273572
"""
35283573
if inclusive:
35293574
lmask = self >= left

0 commit comments

Comments
 (0)