Pandas DataFrame | isin method
Start your free 7-days trial now!
Pandas DataFrame.isin(~) method checks if certain values are present in the DataFrame.
Parameters
1. values | array or dict
The values whose presence you want to check for in the DataFrame.
Return Value
A DataFrame of booleans, where True represents a match between a value in the DataFrame and the specified value(s).
Examples
Consider the following DataFrame:
df
A B0 1 31 2 4
Checking for the presence of certain values
In the entire DataFrame
To check for the presence of certain values in the entire DataFrame, provide an array like follows:
df.isin([1,3])
A B0 True True1 False False
Here, cells A0 and B0 are flagged as True because they contain the values 1 and 3 respectively,
In certain columns
We can specify which columns to check by providing a dict, like follows:
df.isin({"A":[1,3]})
A B0 True False1 False False
Here, even though cell B0 contains the value 3, it is still flagged as False. This is because we have specified in the argument that we are only interested in checking for the values at column A - all other columns are ignored and automatically flagged as False.