@@ -3396,8 +3396,11 @@ def map(self, mapper, na_action=None):
3396
3396
3397
3397
def isin (self , values , level = None ):
3398
3398
"""
3399
+ Return a boolean array where the index values are 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. The length of the returned boolean array matches
3403
+ the length of the index.
3401
3404
3402
3405
Parameters
3403
3406
----------
@@ -3406,23 +3409,74 @@ 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
3414
level : str or int, optional
3412
3415
Name or position of the index level to use (if the index is a
3413
- MultiIndex).
3416
+ `MultiIndex`).
3417
+
3418
+ Returns
3419
+ -------
3420
+ is_contained : ndarray
3421
+ NumPy array of boolean values.
3422
+
3423
+ See also
3424
+ --------
3425
+ Series.isin : Same for Series.
3426
+ DataFrame.isin : Same method for DataFrames.
3414
3427
3415
3428
Notes
3416
3429
-----
3430
+ In the case of `MultiIndex` you must either specify `values` as a
3431
+ list-like object containing tuples that are the same length as the
3432
+ number of levels, or specify `level`. Otherwise it will raise a
3433
+ ``ValueError``.
3434
+
3417
3435
If `level` is specified:
3418
3436
3419
3437
- if it is the name of one *and only one* index level, use that level;
3420
3438
- otherwise it should be a number indicating level position.
3421
3439
3422
- Returns
3423
- -------
3424
- is_contained : ndarray (boolean dtype)
3440
+ Examples
3441
+ --------
3442
+ >>> idx = pd.Index([1,2,3])
3443
+ >>> idx
3444
+ Int64Index([1, 2, 3], dtype='int64')
3445
+
3446
+ Check whether each index value in a list of values.
3447
+ >>> idx.isin([1, 4])
3448
+ array([ True, False, False])
3449
+
3450
+ >>> midx = pd.MultiIndex.from_arrays([[1,2,3],
3451
+ ... ['red', 'blue', 'green']],
3452
+ ... names=('number', 'color'))
3453
+ >>> midx
3454
+ MultiIndex(levels=[[1, 2, 3], ['blue', 'green', 'red']],
3455
+ labels=[[0, 1, 2], [2, 0, 1]],
3456
+ names=['number', 'color'])
3457
+
3458
+ Check whether the strings in the 'color' level of the MultiIndex
3459
+ are in a list of colors.
3460
+
3461
+ >>> midx.isin(['red', 'orange', 'yellow'], level='color')
3462
+ array([ True, False, False])
3463
+
3464
+ To check across the levels of a MultiIndex, pass a list of tuples:
3465
+
3466
+ >>> midx.isin([(1, 'red'), (3, 'red')])
3467
+ array([ True, False, False])
3468
+
3469
+ For a DatetimeIndex, string values in `values` are converted to
3470
+ Timestamps.
3471
+
3472
+ >>> dates = ['2000-03-11', '2000-03-12', '2000-03-13']
3473
+ >>> dti = pd.to_datetime(dates)
3474
+ >>> dti
3475
+ DatetimeIndex(['2000-03-11', '2000-03-12', '2000-03-13'],
3476
+ dtype='datetime64[ns]', freq=None)
3425
3477
3478
+ >>> dti.isin(['2000-03-11'])
3479
+ array([ True, False, False])
3426
3480
"""
3427
3481
if level is not None :
3428
3482
self ._validate_index_level (level )
0 commit comments