當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。