Primary
Series.isin() ⚬|Documentation|1st|20251021151429-00-⌔
pandas.Series.isin — pandas 2.3.3 documentation#pandas.Series.isin
Series.isin(values)Whether elements in Series are contained in values.
Return a boolean Series showing whether each element in the Series matches an element in the passed sequence of values exactly.
Parameters:
values: set or list-likeThe 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.Returns:
Series
Series of booleans indicating if each element is in values.
Raises:
TypeError
- If values is a string
See also:
DataFrame.isinEquivalent method on DataFrame.
Examples:
>>> s = pd.Series( ... ["llama", "cow", "llama", "beetle", "llama", "hippo"], name="animal" ... ) >>> s.isin(["cow", "llama"]) 0 True 1 True 2 True 3 False 4 True 5 False Name: animal, dtype: boolTo invert the boolean values, use the
~operator:>>> ~s.isin(["cow", "llama"]) 0 False 1 False 2 False 3 True 4 False 5 True Name: animal, dtype: boolPassing a single string as
s.isin('llama')will raise an error. Use a list of one element instead:>>> s.isin(["llama"]) 0 True 1 False 2 True 3 False 4 True 5 False Name: animal, dtype: boolStrings and integers are distinct and are therefore not comparable:
>>> pd.Series([1]).isin(["1"]) 0 False dtype: bool >>> pd.Series([1.1]).isin(["1.1"]) 0 False dtype: boolPrinted 2026-06-28.
(echo:: @ ᯤ)
Link to original
Secondary
• • •