6

I have a dataframe where some of the SongIds are repeated. I would like to extract those rows which have the repetition. Any idea how? Tried:

dfB[dfB.SongId.duplicated()]

But didn't work well.

This is an example of my dataframe. SongId 0, 10 and 16 are repeated in this example:

enter image description here

joe borg
  • 133
  • 1
  • 1
  • 7

1 Answers1

16

try this,

df=pd.DataFrame({"Song ID":[0,0,1,3,1,4,5],'ArtistID':[12,13,34,1,21,43,22]})
print df[df.duplicated(subset=['Song ID'],keep=False)]

Output:

   Song ID  value
0        0     12
1        0     13
2        1     34
4        1     21
Mohamed Thasin ah
  • 10,754
  • 11
  • 52
  • 111