pandas.Index.where
- Index.where(cond, other=None)[source]
-
Replace values where the condition is False.
The replacement is taken from other.
- Parameters
-
- cond:bool array-like with the same length as self
-
Condition to select the values on.
- other:scalar, or array-like, default None
-
Replacement if the condition is False.
- Returns
-
- pandas.Index
-
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')
© 2008–2021, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/1.3.4/reference/api/pandas.Index.where.html