pandas 1.4.2

ParametersRaisesReturnsBackRef
isin(self, values) -> 'Series'

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

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.

Raises

TypeError
  • If :None:None:`values` is a string

Returns

Series

Series of booleans indicating if each element is in values.

Whether elements in Series are contained in :None:None:`values`.

See Also

DataFrame.isin

Equivalent method on DataFrame.

Examples

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

To invert the boolean values, use the ~ operator:

This example is valid syntax, but we were not able to check execution
>>> ~s.isin(['cow', 'lama'])
0    False
1    False
2    False
3     True
4    False
5     True
Name: animal, dtype: bool

Passing a single string as s.isin('lama') will raise an error. Use a list of one element instead:

This example is valid syntax, but we were not able to check execution
>>> s.isin(['lama'])
0     True
1    False
2     True
3    False
4     True
5    False
Name: animal, dtype: bool

Strings and integers are distinct and are therefore not comparable:

This example is valid syntax, but we were not able to check execution
>>> pd.Series([1]).isin(['1'])
0    False
dtype: bool
This example is valid syntax, but we were not able to check execution
>>> pd.Series([1.1]).isin(['1.1'])
0    False
dtype: bool
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.arrays.categorical.Categorical.isin pandas.core.frame.DataFrame.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/series.py#5068
type: <class 'function'>
Commit: