Index.
where
Replace values where the condition is False.
The replacement is taken from other.
Condition to select the values on.
Replacement if the condition is False.
A copy of self with values replaced from other where the condition is False.
See also
Series.where
Same method for Series.
DataFrame.where
Same method for DataFrame.
Examples
>>> idx = pd.Index(['car', 'bike', 'train', 'tractor']) >>> idx Index(['car', 'bike', 'train', 'tractor'], dtype='object') >>> idx.where(idx.isin(['car', 'train']), 'other') Index(['car', 'other', 'train', 'other'], dtype='object')