pandas.Index.where#

final Index.where(cond, other=None)[源代码]#

替换条件为FALSE的值。

替代者是从其他人那里取来的。

参数
cond与自身长度相同的类布尔数组

用于选择值的条件。

other标量或类似数组,默认为无

如果条件为假,则替换。

退货
pandas.Index

条件为FALSE的情况下替换了OTHER中的值的SELF副本。

参见

Series.where

对系列采用相同的方法。

DataFrame.where

DataFrame也采用同样的方法。

示例

>>> 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')