2

I have a dataframe with codes, registered in different times (columns). Like this way:

   time1 time2 time3  time4
0  A09.9 B25   A02.2  NaN
1  B21   J2    Z23.1  J2
2  C21.2 C03   NaN    NaN

I need to remove the rows with duplicate values in any column, so in this case it would be the second row.

   time1 time2 time3  time4
0  A09.9 B25   A02.2  NaN
1  C21.2 C03   NaN    NaN

I haven't found any efficient way, just going from row to row.

1 Answer 1

6

We using nuinque with notnull value count

df[df.nunique(1)==df.notnull().sum(1)]
Out[154]: 
   time1 time2  time3 time4
0  A09.9   B25  A02.2   NaN
2  C21.2   C03    NaN   NaN
Sign up to request clarification or add additional context in comments.

1 Comment

That's nice! I was thinking about a version with melt combined with groupby, but I guess that would not have come close to the performance of this solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.