Skip to content

Commit 90c00c7

Browse files
committed
DOC: Improve documentation for Index.where
1 parent 49c0c8d commit 90c00c7

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

pandas/core/indexes/base.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3936,37 +3936,35 @@ def memory_usage(self, deep: bool = False) -> int:
39363936

39373937
def where(self, cond, other=None):
39383938
"""
3939-
Return a copy of self with entries replaced where cond is False.
3939+
Replace values where the condition is False.
39403940
39413941
The replacement is taken from other.
39423942
39433943
Parameters
39443944
----------
39453945
cond : bool array-like with the same length as self
3946-
Condition to select the entries on.
3946+
Condition to select the values on.
39473947
other : scalar, or array-like, default None
39483948
Replacement if the condition is False.
39493949
39503950
Returns
39513951
-------
39523952
pandas.Index
3953-
Copy of self with entries replaced from other
3953+
A copy of self with values replaced from other
39543954
where the condition is False.
39553955
39563956
See Also
39573957
--------
3958-
DataFrame.where : Replace values in a DataFrame where the condition is False.
3958+
Series.where : Same method for Series.
3959+
DataFrame.where : Same method for DataFrame.
39593960
39603961
Examples
39613962
--------
3962-
>>> idx1 = pd.Index([42, 21, 34, 96, 72])
3963-
>>> idx1
3964-
Int64Index([42, 21, 34, 96, 72], dtype='int64')
3965-
>>> idx2 = pd.Index([140, 150, 140, 190, 170])
3966-
>>> idx2
3967-
Int64Index([140, 150, 140, 190, 170], dtype='int64')
3968-
>>> idx1.where((idx2 - 100) > idx1, idx2)
3969-
Int64Index([140, 21, 34, 190, 170], dtype='int64')
3963+
>>> idx = pd.Index(['car', 'bike', 'train', 'tractor'])
3964+
>>> idx
3965+
Index(['car', 'bike', 'train', 'tractor'], dtype='object')
3966+
>>> idx.where(idx.isin(['car', 'train']), 'other')
3967+
Index(['car', 'other', 'train', 'other'], dtype='object')
39703968
"""
39713969
if other is None:
39723970
other = self._na_value

0 commit comments

Comments
 (0)