简体   繁体   English

如何计算 Pandas 中的重复项?

[英]How to count duplicates in Pandas?

I use this pattern to find duplicates in column A from set duplicates :我使用此模式从 set duplicates中查找列 A 中的重复项:

duplicates = {1, 2, 3}
df[~df['A'].isin(duplicates)]

It works and returns me rows witout duplicates.它可以工作并返回没有重复的行。 But how to get count of duplicates?但是如何获得重复数?

I have tried these:我试过这些:

df[~df['A'].isin(duplicates)].count()
~df['A'].isin(duplicates).count()

And how to extract this count to variable.以及如何将此计数提取到变量中。

new_df = df[~df['A'].isin(duplicates)]
new_df['duplicate_values'] = new_df.duplicated('A')
new_df['duplicate_values'].sum()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM