pandas.Series.isin

Check whether values are contained in Series.

Return a boolean Series showing whether each element in the Series matches an element in the passed sequence of values exactly.

param values
set or list-like

The sequence of values to test. Passing in a single string will raise a TypeError. Instead, turn a single string into a list of one element.

New in version 0.18.1.

Support for values as a set.

return

Series Series of booleans indicating if each element is in values.

raises
TypeError
  • If values is a string

Limitations

  • This function may reveal slower performance than Pandas* on user system. Users should exercise a tradeoff

    between staying in JIT-region with that function or going back to interpreter mode.

Examples

Check whether values are contained in Series.
import numpy as np
import pandas as pd
from numba import njit


@njit
def series_isin():
    s = pd.Series([4, np.nan, 2, 1])

    return s.isin([4, 1])  # Expect series of True, False, False, True


print(series_isin())
$ python ./series/series_isin.py
0     True
1    False
2    False
3     True
dtype: bool

See also

DataFrame.isin

Equivalent method on DataFrame.