isin() method is used to filter data frames. The
isin () method helps in selecting rows with a specific (or multiple) value in a specific column.
Syntax: DataFrame.isin (values )
values: iterable, Series, List, Tuple, DataFrame or dictionary to check in the caller Series / Data Frame .
Return Type: DataFrame of Boolean of Dimension.
To download the CSV file you are using, press here.
Example # 1: Filtering one parameter
In the following The example tests strings and returns a Boolean series that is True wherever gender = "male". The series is then passed into the dataframe to see the new filtered dataframe.
As shown in the output image, only lines with gender = male are returned.
Example # 2: Filtering Multiple Parameters
In the following example, a data frame is filtered by both gender and team. Rows with gender = "Female" and "Team" = "Engineering", "Distribution" or "Finance" are returned.
# import pandas package
pandas as pd
# create data frame from CSV file
# create bool series filters from isin ()
]. isin ([
]. isin ([
" Finance "
# displaying data with filter applied and required
data [filter1 & amp; filter2]
As shown in the output image, rows having gender = "Female" and "Team" = "Engineering", "Allocation" or "Finance" are returned.