mars.dataframe.Index.drop_duplicates#
- Index.drop_duplicates(keep='first', method='auto')#
返回去除重复值的索引。
- Parameters
keep ({‘first’, ‘last’,
False}, default ‘first’) –‘first’ : 除首次出现外,删除重复项。
’last’ : 除最后一次出现外,删除重复项。
False: 删除所有重复项。
- Returns
去重
- Return type
另请参阅
Series.drop_duplicates在 Series 上的等效方法。
DataFrame.drop_duplicates数据框上的等效方法。
Index.duplicated与索引相关的方法,指示重复的索引值。
示例
生成一个带有重复值的 pandas.Index。
>>> import mars.dataframe as md
>>> idx = md.Index(['lame', 'cow', 'lame', 'beetle', 'lame', 'hippo'])
“keep” 参数控制哪些重复值被移除。 值为“first”会保留每组重复条目的第一次出现。 keep 的默认值为“first”。
>>> idx.drop_duplicates(keep='first').execute() Index(['lame', 'cow', 'beetle', 'hippo'], dtype='object')
值‘last’保留每组重复条目的最后一次出现。
>>> idx.drop_duplicates(keep='last').execute() Index(['cow', 'beetle', 'lame', 'hippo'], dtype='object')
值
False会丢弃所有重复条目的集合。>>> idx.drop_duplicates(keep=False).execute() Index(['cow', 'beetle', 'hippo'], dtype='object')