详情见官方(https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.duplicated.html)
例子 >>> df = pd.DataFrame({ 'brand': ['YumYum','YumYum', 'YumYum', 'Indomie', 'Indomie', 'Indomie'], 'style': ['cup','cup', 'cup', 'cup', 'pack', 'pack'], 'rating': [4, 4, 4, 3.5, 15, 5]})>>> df brand style rating0 YumYum cup 4.01 YumYum cup 4.02 YumYum cup 4.03 Indomie cup 3.54 Indomie pack 15.05 Indomie pack 5.0默认情况下,对于每一组重复的值,第一次出现的值设置为False,其他所有值设置为True
>>> df.duplicated()0 False1 True2 True3 False4 False5 Falsedtype: bool>>> type(df.duplicated())<class 'pandas.core.series.Series'>通过使用' last ',每组重复值的最后一次出现被设置为False,而其他所有重复值被设置为True。
>>> df.duplicated(keep='last')0 True1 True2 False3 False4 False5 Falsedtype: bool使用子subset查找特定列上的重复项。
>>> df.duplicated(subset=['brand'])0 False1 True2 True3 False4 True5 Truedtype: bool通过将keep设置为False,所有重复项都为True。
>>> df.duplicated(keep=False)0 True1 True2 True3 False4 False5 Falsedtype: bool