Using the isin method with multiple conditions

We can also use the isin method to filter rows based on values from multiple columns. In order to perform this, we pass a dictionary object where keys are column names, and values are lists of values for those columns from which we want to select records.

Taking an example, let's select values where the State parameter is California and the Metro parameter is San Francisco. We create a dictionary object with these two columns containing the values we want to select, and then we pass this dictionary item to the isin method, and call the isin method on the dataset. We then pass the filter to the DataFrame and select our records, as follows:

filter = data.isin({'State': ['CA'], 'Metro': ['San Francisco']}) ...

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.