Skip to content

Commit 9a8e83a

Browse files
authored
DOC: Improve documentation for Index.where (#32009)
1 parent d8115ce commit 9a8e83a

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

pandas/core/indexes/base.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -3937,18 +3937,35 @@ def memory_usage(self, deep: bool = False) -> int:
39373937

39383938
def where(self, cond, other=None):
39393939
"""
3940-
Return an Index of same shape as self and whose corresponding
3941-
entries are from self where cond is True and otherwise are from
3942-
other.
3940+
Replace values where the condition is False.
3941+
3942+
The replacement is taken from other.
39433943
39443944
Parameters
39453945
----------
39463946
cond : bool array-like with the same length as self
3947-
other : scalar, or array-like
3947+
Condition to select the values on.
3948+
other : scalar, or array-like, default None
3949+
Replacement if the condition is False.
39483950
39493951
Returns
39503952
-------
3951-
Index
3953+
pandas.Index
3954+
A copy of self with values replaced from other
3955+
where the condition is False.
3956+
3957+
See Also
3958+
--------
3959+
Series.where : Same method for Series.
3960+
DataFrame.where : Same method for DataFrame.
3961+
3962+
Examples
3963+
--------
3964+
>>> idx = pd.Index(['car', 'bike', 'train', 'tractor'])
3965+
>>> idx
3966+
Index(['car', 'bike', 'train', 'tractor'], dtype='object')
3967+
>>> idx.where(idx.isin(['car', 'train']), 'other')
3968+
Index(['car', 'other', 'train', 'other'], dtype='object')
39523969
"""
39533970
if other is None:
39543971
other = self._na_value

0 commit comments

Comments
 (0)