pandas get only duplicates code example
Example 1: print duplicates elements in column pandas
mask = df.columnname.duplicated(keep=False)
print (df[mask])
Example 2: keep only one duplicate in pandas
import pandas as pd
df = pd.DataFrame({"A":["foo", "foo", "foo", "bar"], "B":[0,1,1,1], "C":["A","A","B","A"]})
df.drop_duplicates(subset=['A', 'C'], keep=False)