Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Iterate through rows of pandas df and drop rows which violate rules

I have a df, and I just want to iterate through the rows and if the same value is in the row more than once, drop the row from the df.

Ex: Row1 = 1, 2, 3, 4
    Row2 = 1, 2, 3, 1
    Row3 = 2, 3, 5, 7

For my case, Row2 would be dropped because 1 shows up twice.

I am familiar with iterrows, but I am struggling to form the actual logic needed to accomplish my task.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try with nunqiue

out = df[df.nunique(1)==df.shape[1]]
Out[97]: 
   1  2  3  4
0  1  2  3  4
2  2  3  5  7
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading