pandas.Index.where#
- final Index.where(cond, other=None)[源代码]#
替换条件为False的值。
替换值从 other 中获取。
- Parameters:
- cond与 self 长度相同的布尔数组。
选择值的条件。
- other标量或类数组,默认为 None
条件为 False 时的替换值。
- Returns:
- pandas.Index
self 的副本,其中条件为 False 的值被 other 中的值替换。
参见
Series.whereSeries 的相同方法。
DataFrame.whereDataFrame 的相同方法。
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')