...

/

Relational and Logical Operators with Pandas Series

Relational and Logical Operators with Pandas Series

Let's find out how to use relational operators to compare the values of a pandas series.

We'll cover the following...

Try it yourself

Try executing the code below to see the result.

Press + to interact
import pandas as pd
nums = pd.Series([1, 2, 3, 4, 5, 6])
print(nums[(nums > 2) and (nums < 5)])

Explanation

The result of nums > 2 is the series of Boolean values listed below:

In [1]: nums>2
Out[1]:
0 False
1 False
2 True
3 True
4 True
5 True
dtype: bool

We can use this Boolean series to select parts ...