Skip to content

Commit bf6307b

Browse files
committed
DOC: update the Index.isin docstring
1 parent c3d491a commit bf6307b

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

pandas/core/indexes/base.py

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

31133113
def isin(self, values, level=None):
31143114
"""
3115+
Boolean array on existence of index values in `values`.
3116+
31153117
Compute boolean array of whether each index value is found in the
3116-
passed set of values.
3118+
passed set of values. Length of the returned boolean array matches
3119+
the length of the index.
31173120
31183121
Parameters
31193122
----------
@@ -3122,23 +3125,67 @@ def isin(self, values, level=None):
31223125
31233126
.. versionadded:: 0.18.1
31243127
3125-
Support for values as a set
3128+
Support for values as a set.
31263129
3127-
level : str or int, optional
3130+
level : str or int, optional in the case of Index, compulsory on
3131+
MultiIndex
31283132
Name or position of the index level to use (if the index is a
31293133
MultiIndex).
31303134
3135+
Returns
3136+
-------
3137+
is_contained : ndarray (boolean dtype)
3138+
3139+
See also
3140+
--------
3141+
DatetimeIndex.isin : an Index of :class:`Datetime` s
3142+
TimedeltaIndex : an Index of :class:`Timedelta` s
3143+
PeriodIndex : an Index of :class:`Period` s
3144+
MultiIndex.isin : Same for `MultiIndex`
3145+
NumericIndex.isin : Same for `Int64Index`, `UInt64Index`,
3146+
`Float64Index`
3147+
31313148
Notes
31323149
-----
31333150
If `level` is specified:
31343151
31353152
- if it is the name of one *and only one* index level, use that level;
31363153
- otherwise it should be a number indicating level position.
31373154
3138-
Returns
3139-
-------
3140-
is_contained : ndarray (boolean dtype)
3155+
Examples
3156+
--------
3157+
>>> idx = pd.Index([1,2,3])
3158+
>>> idx
3159+
Int64Index([1, 2, 3], dtype='int64')
3160+
3161+
Check whether a value is in the Index:
3162+
>>> idx.isin([1])
3163+
array([ True, False, False])
3164+
3165+
>>> midx = pd.MultiIndex.from_arrays([[1,2,3],
3166+
... ['red','blue','green']],
3167+
... names=('number', 'color'))
3168+
>>> midx
3169+
MultiIndex(levels=[[1, 2, 3], ['blue', 'green', 'red']],\
3170+
labels=[[0, 1, 2], [2, 0, 1]],\
3171+
names=['number', 'color'])
3172+
3173+
Check whether a string index value is in the 'color' level of the
3174+
MultiIndex:
3175+
3176+
>>> midx.isin(['red'],'color')
3177+
array([ True, False, False])
3178+
3179+
>>> dates = ['3/11/2000', '3/12/2000', '3/13/2000']
3180+
>>> dti = pd.to_datetime(dates)
3181+
>>> dti
3182+
DatetimeIndex(['2000-03-11', '2000-03-12', '2000-03-13'],\
3183+
dtype='datetime64[ns]', freq=None)
3184+
3185+
Check whether a datetime index value is in the DatetimeIndex:
31413186
3187+
>>> dti.isin(['3/11/2000'])
3188+
array([ True, False, False])
31423189
"""
31433190
if level is not None:
31443191
self._validate_index_level(level)

0 commit comments

Comments
 (0)