用法:
Index.drop_duplicates(keep='first')
返回删除重复值的索引。
- keep:
{‘first’, ‘last’,
False
},默认 ‘first’ ‘first’:删除除第一次出现的重复项。
‘last’:删除除最后一次之外的重复项。
False
:删除所有重复项。
- keep:
- deduplicated: index
参数:
返回:
例子:
生成具有重复值的 pandas.Index。
>>> idx = pd.Index(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'])
keep
参数控制删除哪些重复值。值‘first’ 保留每组重复条目的第一次出现。保持的默认值为‘first’。>>> idx.drop_duplicates(keep='first') Index(['lama', 'cow', 'beetle', 'hippo'], dtype='object')
值 ‘last’ 保留每组重复条目的最后一次出现。
>>> idx.drop_duplicates(keep='last') Index(['cow', 'beetle', 'lama', 'hippo'], dtype='object')
值
False
丢弃所有重复条目集。>>> idx.drop_duplicates(keep=False) Index(['cow', 'beetle', 'hippo'], dtype='object')
相关用法
- Python pandas.Index.droplevel用法及代码示例
- Python pandas.Index.duplicated用法及代码示例
- Python pandas.Index.difference用法及代码示例
- Python pandas.Index.delete用法及代码示例
- Python pandas.Index.value_counts用法及代码示例
- Python pandas.Index.argmin用法及代码示例
- Python pandas.Index.is_categorical用法及代码示例
- Python pandas.Index.to_series用法及代码示例
- Python pandas.Index.str用法及代码示例
- Python pandas.Index.to_numpy用法及代码示例
- Python pandas.Index.is_object用法及代码示例
- Python pandas.Index.slice_indexer用法及代码示例
- Python pandas.Index.is_interval用法及代码示例
- Python pandas.Index.notnull用法及代码示例
- Python pandas.Index.equals用法及代码示例
- Python pandas.Index.set_names用法及代码示例
- Python pandas.Index.searchsorted用法及代码示例
- Python pandas.Index.is_monotonic_increasing用法及代码示例
- Python pandas.Index.min用法及代码示例
- Python pandas.Index.is_monotonic_decreasing用法及代码示例
注:本文由纯净天空筛选整理自pandas.pydata.org大神的英文原创作品 pandas.Index.drop_duplicates。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。