Skip to content
Related Articles

Related Articles

Improve Article

Python | Pandas Series.between()

  • Last Updated : 17 Sep, 2018

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Pandas between() method is used on series to check which values lie between first and second argument.

Syntax: Series.between(left, right, inclusive=True)


left: A scalar value that defines the left boundary
right: A scalar value that defines the right boundary
inclusive: A Boolean value which is True by default. If False, it excludes the two passed arguments while checking.

Return Type: A Boolean series which is True for every element that lies between the argument values.

To download the CSV file used, Click Here.

Example #1:Values of salary column are checked. If they lie between 80000 and 100000, True is returned.

# importing pandas package
import pandas as pd
# making data frame from csv file
data = pd.read_csv("employees.csv")
# making a bool series
bool_series = data["Salary"].between(80000, 100000, inclusive = True)
# returning dataframe with salary between above values

As shown in the output image, the data frame is having rows only with salary between 80000 and 100000.

Error and exceptions:

  • This method doesn’t work on strings.
  • This method is only for Series (1D data frame)

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :