I use this pattern to find duplicates in column A from set duplicates
:
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.