pandas 1.4.2

ParametersReturnsBackRef
isin(self, values) -> 'DataFrame'

Parameters

values : iterable, Series, DataFrame or dict

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

Returns

DataFrame

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

Whether each element in the DataFrame is contained in values.

See Also

DataFrame.eq

Equality test for DataFrame.

Series.isin

Equivalent method on Series.

Series.str.contains

Test if pattern or regex is contained within a string of a Series or Index.

Examples

This example is valid syntax, but we were not able to check execution
>>> 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

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)

This example is valid syntax, but we were not able to check execution
>>> df.isin([0, 2])
        num_legs  num_wings
falcon      True       True
dog        False       True

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

This example is valid syntax, but we were not able to check execution
>>> ~df.isin([0, 2])
        num_legs  num_wings
falcon     False      False
dog         True      False

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

This example is valid syntax, but we were not able to check execution
>>> df.isin({'num_wings': [0, 3]})
        num_legs  num_wings
falcon     False      False
dog        False       True

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.

This example is valid syntax, but we were not able to check execution
>>> 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
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.indexes.multi.MultiIndex.isin pandas.core.indexes.base.Index.isin pandas.core.series.Series.isin

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/frame.py#10650
type: <class 'function'>
Commit: