MCPcopy
hub / github.com/pandas-dev/pandas / isin

Method isin

pandas/core/indexes/base.py:6675–6746  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

test_isinMethod · 0.95
test_isin_level_kwargMethod · 0.95
test_isin_emptyMethod · 0.95
test_isin_string_nullMethod · 0.95
wide_to_longFunction · 0.45
generate_filter_opMethod · 0.45
_inFunction · 0.45
_not_inFunction · 0.45

Calls 1

_validate_index_levelMethod · 0.95

Tested by 7

test_isinMethod · 0.76
test_isin_level_kwargMethod · 0.76
test_isin_emptyMethod · 0.76
test_isin_string_nullMethod · 0.76