You are viewing documentation about an older version (1.21.0). View latest version

modin.pandas.DataFrame.isin¶

DataFrame.isin(values: ListLike | Series | DataFrame | dict[Hashable, ListLike]) → DataFrame[source]¶

Whether each element in the DataFrame is contained in values.

Parameters:

values (list-like, Series, DataFrame or dict) –

The result will only be true at a location if all the labels match. If values is a Series, that’s the index. If values is a dict, the keys must be the column names, which must match. If values is a DataFrame, then both the index and column labels must match.

Snowpark pandas assumes that in the case of values being Series or DataFrame that the index of values is unique (i.e., values.index.is_unique() = True)

Returns:

DataFrame of booleans showing whether each element in the DataFrame is contained in values.

Return type:

DataFrame

Examples

>>> df = pd.DataFrame({'num_legs': [2, 4], 'num_wings': [2, 0]},
...                   index=['falcon', 'dog'])
>>> df
        num_legs  num_wings
falcon         2          2
dog            4          0
Copy

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)

>>> df.isin([0, 2])
        num_legs  num_wings
falcon      True       True
dog        False       True
Copy

To check if values is not in the DataFrame, use the ~ operator:

>>> ~df.isin([0, 2])
        num_legs  num_wings
falcon     False      False
dog         True      False
Copy

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

>>> df.isin({'num_wings': [0, 3]})
        num_legs  num_wings
falcon     False      False
dog        False       True
Copy

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

>>> other = pd.DataFrame({'num_legs': [8, 3], 'num_wings': [0, 2]},
...                      index=['spider', 'falcon'])
>>> df.isin(other)
        num_legs  num_wings
falcon     False       True
dog        False      False
Copy

Caution

Snowpark pandas does not perform a check for the case that values is a DataFrame or Series nor does it check whether the index is unique. Snowpark pandas preserves NULL values; if the DataFrame contains NULL in a cell the output cell will be NULL.