@@ -3396,10 +3396,10 @@ def map(self, mapper, na_action=None):
3396
3396
3397
3397
def isin (self , values , level = None ):
3398
3398
"""
3399
- Boolean array on existence of index values in `values`.
3399
+ Return a boolean array where the index values are in `values`.
3400
3400
3401
3401
Compute boolean array of whether each index value is found in the
3402
- passed set of values. Length of the returned boolean array matches
3402
+ passed set of values. The length of the returned boolean array matches
3403
3403
the length of the index.
3404
3404
3405
3405
Parameters
@@ -3411,26 +3411,25 @@ def isin(self, values, level=None):
3411
3411
3412
3412
Support for values as a set.
3413
3413
3414
- level : str or int, optional in the case of Index, compulsory on
3415
- MultiIndex
3414
+ level : str or int, optional
3416
3415
Name or position of the index level to use (if the index is a
3417
- MultiIndex).
3416
+ ` MultiIndex` ).
3418
3417
3419
3418
Returns
3420
3419
-------
3421
3420
is_contained : ndarray (boolean dtype)
3422
3421
3423
3422
See also
3424
3423
--------
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`
3424
+ Series.isin: same for :class:`~pandas.Series`
3431
3425
3432
3426
Notes
3433
3427
-----
3428
+ In the case of `MultiIndex` you must either specify `values` as a
3429
+ list-like object containing tuples that are the same length as the
3430
+ number of levels, or specify `level`. Otherwise it will raise
3431
+ `ValueError`.
3432
+
3434
3433
If `level` is specified:
3435
3434
3436
3435
- if it is the name of one *and only one* index level, use that level;
@@ -3450,21 +3449,26 @@ def isin(self, values, level=None):
3450
3449
... ['red','blue','green']],
3451
3450
... names=('number', 'color'))
3452
3451
>>> midx
3453
- MultiIndex(levels=[[1, 2, 3], ['blue', 'green', 'red']],\
3454
- labels=[[0, 1, 2], [2, 0, 1]],\
3455
- names=['number', 'color'])
3452
+ MultiIndex(levels=[[1, 2, 3], ['blue', 'green', 'red']],
3453
+ labels=[[0, 1, 2], [2, 0, 1]],
3454
+ names=['number', 'color'])
3456
3455
3457
3456
Check whether a string index value is in the 'color' level of the
3458
3457
MultiIndex:
3459
3458
3460
- >>> midx.isin(['red'],'color')
3459
+ >>> midx.isin(['red'], level='color')
3460
+ array([ True, False, False])
3461
+
3462
+ Check whether a pair of indexes is in the MultiIndex:
3463
+
3464
+ >>> midx.isin([(1, 'red'), (3, 'red')])
3461
3465
array([ True, False, False])
3462
3466
3463
3467
>>> dates = ['3/11/2000', '3/12/2000', '3/13/2000']
3464
3468
>>> dti = pd.to_datetime(dates)
3465
3469
>>> dti
3466
- DatetimeIndex(['2000-03-11', '2000-03-12', '2000-03-13'],\
3467
- dtype='datetime64[ns]', freq=None)
3470
+ DatetimeIndex(['2000-03-11', '2000-03-12', '2000-03-13'],
3471
+ dtype='datetime64[ns]', freq=None)
3468
3472
3469
3473
Check whether a datetime index value is in the DatetimeIndex:
3470
3474
0 commit comments