Return a boolean array where the index values are in `values`. Compute boolean array of whether each index value is found in the passed set of values. The length of the returned boolean array matches the length of the index. Parameters ----------
(self, values, level: str_t | int | None = None)
| 6673 | return Index(items, name=self.name, tupleize_cols=False) |
| 6674 | |
| 6675 | def isin(self, values, level: str_t | int | None = None) -> npt.NDArray[np.bool_]: |
| 6676 | """ |
| 6677 | Return a boolean array where the index values are in `values`. |
| 6678 | |
| 6679 | Compute boolean array of whether each index value is found in the |
| 6680 | passed set of values. The length of the returned boolean array matches |
| 6681 | the length of the index. |
| 6682 | |
| 6683 | Parameters |
| 6684 | ---------- |
| 6685 | values : set or list-like |
| 6686 | Sought values. |
| 6687 | level : str or int, optional |
| 6688 | Name or position of the index level to use (if the index is a |
| 6689 | `MultiIndex`). |
| 6690 | |
| 6691 | Returns |
| 6692 | ------- |
| 6693 | np.ndarray[bool] |
| 6694 | NumPy array of boolean values. |
| 6695 | |
| 6696 | See Also |
| 6697 | -------- |
| 6698 | Series.isin : Same for Series. |
| 6699 | DataFrame.isin : Same method for DataFrames. |
| 6700 | |
| 6701 | Notes |
| 6702 | ----- |
| 6703 | In the case of `MultiIndex` you must either specify `values` as a |
| 6704 | list-like object containing tuples that are the same length as the |
| 6705 | number of levels, or specify `level`. Otherwise it will raise a |
| 6706 | ``ValueError``. |
| 6707 | |
| 6708 | If `level` is specified: |
| 6709 | |
| 6710 | - if it is the name of one *and only one* index level, use that level; |
| 6711 | - otherwise it should be a number indicating level position. |
| 6712 | |
| 6713 | Examples |
| 6714 | -------- |
| 6715 | >>> idx = pd.Index([1, 2, 3]) |
| 6716 | >>> idx |
| 6717 | Index([1, 2, 3], dtype='int64') |
| 6718 | |
| 6719 | Check whether each index value in a list of values. |
| 6720 | |
| 6721 | >>> idx.isin([1, 4]) |
| 6722 | array([ True, False, False]) |
| 6723 | |
| 6724 | >>> midx = pd.MultiIndex.from_arrays( |
| 6725 | ... [[1, 2, 3], ["red", "blue", "green"]], names=["number", "color"] |
| 6726 | ... ) |
| 6727 | >>> midx |
| 6728 | MultiIndex([(1, 'red'), |
| 6729 | (2, 'blue'), |
| 6730 | (3, 'green')], |
| 6731 | names=['number', 'color']) |
| 6732 |