Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List rows which column value is not unique in dataframe [duplicate]

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

like image 995
joe borg Avatar asked Dec 13 '22 16:12

joe borg


1 Answers

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
like image 166
Mohamed Thasin ah Avatar answered Dec 29 '22 11:12

Mohamed Thasin ah