Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.isin#

Series.isin(values)[source]#

Whether elements in Series are contained invalues.

Return a boolean Series showing whether each element in the Seriesmatches an element in the passed sequence ofvalues exactly.

Parameters:
valuesset or list-like

The sequence of values to test. Passing in a single string willraise aTypeError. Instead, turn a single string into alist of one element.

Returns:
Series

Series of booleans indicating if each element is in values.

Raises:
TypeError
  • Ifvalues is a string

See also

DataFrame.isin

Equivalent method on DataFrame.

Examples

>>>s=pd.Series(['llama','cow','llama','beetle','llama',...'hippo'],name='animal')>>>s.isin(['cow','llama'])0     True1     True2     True3    False4     True5    FalseName: animal, dtype: bool

To invert the boolean values, use the~ operator:

>>>~s.isin(['cow','llama'])0    False1    False2    False3     True4    False5     TrueName: animal, dtype: bool

Passing a single string ass.isin('llama') will raise an error. Usea list of one element instead:

>>>s.isin(['llama'])0     True1    False2     True3    False4     True5    FalseName: animal, dtype: bool

Strings and integers are distinct and are therefore not comparable:

>>>pd.Series([1]).isin(['1'])0    Falsedtype: bool>>>pd.Series([1.1]).isin(['1.1'])0    Falsedtype: bool

[8]ページ先頭

©2009-2025 Movatter.jp