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-like The s
(self, values)
| 6000 | return v |
| 6001 | |
| 6002 | def isin(self, values) -> Series: |
| 6003 | """ |
| 6004 | Whether elements in Series are contained in `values`. |
| 6005 | |
| 6006 | Return a boolean Series showing whether each element in the Series |
| 6007 | matches an element in the passed sequence of `values` exactly. |
| 6008 | |
| 6009 | Parameters |
| 6010 | ---------- |
| 6011 | values : set or list-like |
| 6012 | The sequence of values to test. Passing in a single string will |
| 6013 | raise a ``TypeError``. Instead, turn a single string into a |
| 6014 | list of one element. |
| 6015 | |
| 6016 | Returns |
| 6017 | ------- |
| 6018 | Series |
| 6019 | Series of booleans indicating if each element is in values. |
| 6020 | |
| 6021 | Raises |
| 6022 | ------ |
| 6023 | TypeError |
| 6024 | * If `values` is a string |
| 6025 | |
| 6026 | See Also |
| 6027 | -------- |
| 6028 | DataFrame.isin : Equivalent method on DataFrame. |
| 6029 | |
| 6030 | Examples |
| 6031 | -------- |
| 6032 | >>> s = pd.Series( |
| 6033 | ... ["llama", "cow", "llama", "beetle", "llama", "hippo"], name="animal" |
| 6034 | ... ) |
| 6035 | >>> s.isin(["cow", "llama"]) |
| 6036 | 0 True |
| 6037 | 1 True |
| 6038 | 2 True |
| 6039 | 3 False |
| 6040 | 4 True |
| 6041 | 5 False |
| 6042 | Name: animal, dtype: bool |
| 6043 | |
| 6044 | To invert the boolean values, use the ``~`` operator: |
| 6045 | |
| 6046 | >>> ~s.isin(["cow", "llama"]) |
| 6047 | 0 False |
| 6048 | 1 False |
| 6049 | 2 False |
| 6050 | 3 True |
| 6051 | 4 False |
| 6052 | 5 True |
| 6053 | Name: animal, dtype: bool |
| 6054 | |
| 6055 | Passing a single string as ``s.isin('llama')`` will raise an error. Use |
| 6056 | a list of one element instead: |
| 6057 | |
| 6058 | >>> s.isin(["llama"]) |
| 6059 | 0 True |