Filtering based on multiple conditions – OR

We use the same technique to filter data when we pass these conditions with the logical operator OR. Here, we select those records which are from either New York or California. To do this, we join the conditions using the logical operator OR, and pass this combined condition to the dataset. The resulting sub-dataset is from only these two states, as shown here:

data[((data['State'] == 'CA') | (data['State'] == 'NY'))].head() 

The following is the output:

Get Mastering Exploratory Analysis with pandas now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.