Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame({'num_legs': [2, 4], 'num_wings': [2, 0]},
                  index=['eagle', 'cat'])
df
Out[2]:
num_legs num_wings
eagle 2 2
cat 4 0

Pandas: DataFrame - isin.

When values is a list check whether every value in the DataFrame is present in the list
(which animals have 0 or 2 legs or wings)

In [3]:
df.isin([0, 2])
Out[3]:
num_legs num_wings
eagle True True
cat False True

Pandas: DataFrame - When values is a list check whether every value in the DataFrame is present in the list(which animals have 0 and 2 legs or wings).

When values is a dict, we can pass values to check for each column separately:

In [4]:
df.isin({'num_wings': [0, 3]})
Out[4]:
num_legs num_wings
eagle False False
cat False True

Pandas: DataFrame - When values is a dict, we can pass values to check for each column separately.

When values is a Series or DataFrame the index and column must match. Note that ‘eagle’ does
not match based on the number of legs in df2.

In [5]:
other = pd.DataFrame({'num_legs': [8, 2], 'num_wings': [0, 2]},
                     index=['spider', 'eagle'])
df.isin(other)
Out[5]:
num_legs num_wings
eagle True True
cat False False