Skip to content

Commit 1e665ab

Browse files
committed
DOC: update the Index.isin docstring
1 parent 670c2e4 commit 1e665ab

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

Diff for: pandas/core/indexes/base.py

+53-6
Original file line numberDiff line numberDiff line change
@@ -3396,8 +3396,11 @@ def map(self, mapper, na_action=None):
33963396

33973397
def isin(self, values, level=None):
33983398
"""
3399+
Boolean array on existence of index values in `values`.
3400+
33993401
Compute boolean array of whether each index value is found in the
3400-
passed set of values.
3402+
passed set of values. Length of the returned boolean array matches
3403+
the length of the index.
34013404
34023405
Parameters
34033406
----------
@@ -3406,23 +3409,67 @@ def isin(self, values, level=None):
34063409
34073410
.. versionadded:: 0.18.1
34083411
3409-
Support for values as a set
3412+
Support for values as a set.
34103413
3411-
level : str or int, optional
3414+
level : str or int, optional in the case of Index, compulsory on
3415+
MultiIndex
34123416
Name or position of the index level to use (if the index is a
34133417
MultiIndex).
34143418
3419+
Returns
3420+
-------
3421+
is_contained : ndarray (boolean dtype)
3422+
3423+
See also
3424+
--------
3425+
DatetimeIndex.isin : an Index of :class:`Datetime` s
3426+
TimedeltaIndex : an Index of :class:`Timedelta` s
3427+
PeriodIndex : an Index of :class:`Period` s
3428+
MultiIndex.isin : Same for `MultiIndex`
3429+
NumericIndex.isin : Same for `Int64Index`, `UInt64Index`,
3430+
`Float64Index`
3431+
34153432
Notes
34163433
-----
34173434
If `level` is specified:
34183435
34193436
- if it is the name of one *and only one* index level, use that level;
34203437
- otherwise it should be a number indicating level position.
34213438
3422-
Returns
3423-
-------
3424-
is_contained : ndarray (boolean dtype)
3439+
Examples
3440+
--------
3441+
>>> idx = pd.Index([1,2,3])
3442+
>>> idx
3443+
Int64Index([1, 2, 3], dtype='int64')
3444+
3445+
Check whether a value is in the Index:
3446+
>>> idx.isin([1])
3447+
array([ True, False, False])
3448+
3449+
>>> midx = pd.MultiIndex.from_arrays([[1,2,3],
3450+
... ['red','blue','green']],
3451+
... names=('number', 'color'))
3452+
>>> midx
3453+
MultiIndex(levels=[[1, 2, 3], ['blue', 'green', 'red']],\
3454+
labels=[[0, 1, 2], [2, 0, 1]],\
3455+
names=['number', 'color'])
3456+
3457+
Check whether a string index value is in the 'color' level of the
3458+
MultiIndex:
3459+
3460+
>>> midx.isin(['red'],'color')
3461+
array([ True, False, False])
3462+
3463+
>>> dates = ['3/11/2000', '3/12/2000', '3/13/2000']
3464+
>>> dti = pd.to_datetime(dates)
3465+
>>> dti
3466+
DatetimeIndex(['2000-03-11', '2000-03-12', '2000-03-13'],\
3467+
dtype='datetime64[ns]', freq=None)
3468+
3469+
Check whether a datetime index value is in the DatetimeIndex:
34253470
3471+
>>> dti.isin(['3/11/2000'])
3472+
array([ True, False, False])
34263473
"""
34273474
if level is not None:
34283475
self._validate_index_level(level)

0 commit comments

Comments
 (0)