当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python pandas.Index.where用法及代码示例

用法:

final Index.where(cond, other=None)

替换条件为 False 的值。

替换取自其他。

参数

condbool array-like 与自身长度相同

选择值的条件。

other标量,或array-like,默认无

如果条件为 False,则替换。

返回

pandas.Index

一个 self 的副本,其中的值被替换为条件为 False 的 other。

例子

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

相关用法


注:本文由纯净天空筛选整理自pandas.pydata.org大神的英文原创作品 pandas.Index.where。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。