Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
pandas

How to use Series.between() funtion in pandas

Maria Elijah

Overview

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.

Syntax

Series.between(self, left, right, inclusive=True)

Parameters

  • 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.

Example

import pandas as pd
import numpy as np
# create Series 
num_series  = pd.Series([np.nan, 1, 0, 9, 7, 4,np.nan, 2])
 
# using Series.between()
print(num_series.between(1,3))

Explanation

  • 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.

RELATED TAGS

python
pandas
RELATED COURSES

View all Courses

Keep Exploring