mars.dataframe.DataFrame.duplicated#
- DataFrame.duplicated(subset=None, keep='first', method='auto')#
返回表示重复行的布尔系列。
考虑某些列是可选的。
- Parameters
subset (列标签 或 标签序列, 可选) – 仅考虑某些列以识别重复项,默认使用所有列。
keep ({'first', 'last', False}, default 'first') –
确定标记哪些重复项(如果有的话)。
first: 将除了第一次出现的重复项标记为True。last: 将除了最后一次出现的重复项标记为True。False : 将所有重复项标记为
True。
- Returns
每个重复行的布尔系列。
- Return type
另请参阅
Index.duplicated索引上的等效方法。
Series.duplicated在 Series 上的等效方法。
Series.drop_duplicates从序列中移除重复值。
DataFrame.drop_duplicates从DataFrame中移除重复值。
示例
考虑包含拉面评分的数据集。
>>> import mars.dataframe as md
>>> df = md.DataFrame({ ... 'brand': ['Yum Yum', 'Yum Yum', 'Indomie', 'Indomie', 'Indomie'], ... 'style': ['cup', 'cup', 'cup', 'pack', 'pack'], ... 'rating': [4, 4, 3.5, 15, 5] ... }) >>> df.execute() brand style rating 0 Yum Yum cup 4.0 1 Yum Yum cup 4.0 2 Indomie cup 3.5 3 Indomie pack 15.0 4 Indomie pack 5.0
默认情况下,对于每组重复值,第一个出现的值被设置为 False,其他值则设置为 True。
>>> df.duplicated().execute() 0 False 1 True 2 False 3 False 4 False dtype: bool
通过使用‘last’,每组重复值的最后一次出现被设置为 False,其他所有被设置为 True。
>>> df.duplicated(keep='last').execute() 0 True 1 False 2 False 3 False 4 False dtype: bool
通过将
keep设置为 False,所有重复项为 True。>>> df.duplicated(keep=False).execute() 0 True 1 True 2 False 3 False 4 False dtype: bool
要在特定列上查找重复项,请使用
subset。>>> df.duplicated(subset=['brand']).execute() 0 False 1 True 2 False 3 True 4 True dtype: bool