@@ -3937,18 +3937,35 @@ def memory_usage(self, deep: bool = False) -> int:
3937
3937
3938
3938
def where (self , cond , other = None ):
3939
3939
"""
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.
3943
3943
3944
3944
Parameters
3945
3945
----------
3946
3946
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.
3948
3950
3949
3951
Returns
3950
3952
-------
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')
3952
3969
"""
3953
3970
if other is None :
3954
3971
other = self ._na_value
0 commit comments