On this page
pandas.Series.isin
Series.isin(self, values)[source]-
Check whether
valuesare contained in Series.Return a boolean Series showing whether each element in the Series matches an element in the passed sequence of
valuesexactly.Parameters: -
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.
Returns: - Series
-
Series of booleans indicating if each element is in values.
Raises: - TypeError
-
- If
valuesis a string
- If
See also
DataFrame.isin- Equivalent method on DataFrame.
Examples
>>> s = pd.Series(['lama', 'cow', 'lama', 'beetle', 'lama', ... 'hippo'], name='animal') >>> s.isin(['cow', 'lama']) 0 True 1 True 2 True 3 False 4 True 5 False Name: animal, dtype: boolPassing a single string as
s.isin('lama')will raise an error. Use a list of one element instead:>>> s.isin(['lama']) 0 True 1 False 2 True 3 False 4 True 5 False Name: animal, dtype: bool -
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.Series.isin.html