@@ -3396,8 +3396,11 @@ 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`.
3400
+
3399
3401
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.
3401
3404
3402
3405
Parameters
3403
3406
----------
@@ -3406,23 +3409,67 @@ def isin(self, values, level=None):
3406
3409
3407
3410
.. versionadded:: 0.18.1
3408
3411
3409
- Support for values as a set
3412
+ Support for values as a set.
3410
3413
3411
- level : str or int, optional
3414
+ level : str or int, optional in the case of Index, compulsory on
3415
+ MultiIndex
3412
3416
Name or position of the index level to use (if the index is a
3413
3417
MultiIndex).
3414
3418
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
+
3415
3432
Notes
3416
3433
-----
3417
3434
If `level` is specified:
3418
3435
3419
3436
- if it is the name of one *and only one* index level, use that level;
3420
3437
- otherwise it should be a number indicating level position.
3421
3438
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:
3425
3470
3471
+ >>> dti.isin(['3/11/2000'])
3472
+ array([ True, False, False])
3426
3473
"""
3427
3474
if level is not None :
3428
3475
self ._validate_index_level (level )
0 commit comments