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

Get the rows that are not shared between two data frames

I have two data frames with the exact same column, but one of them have 1000 rows (df1), and one of them 500 (df2). The rows of df2 are also found in the data frame df1, but I want the rows that are not.

For example, lets say this is df1:

          Gender       Age
1           F           43
3           F           56
33          M           76
476         F           30
810         M           29

and df2:

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

          Gender       Age
3           F           56
476         F           30

I want a new data frame, df3, that have the unshared rows:

          Gender       Age
1           F           43
33          M           76
810         M           29

How can I do that ?

>Solution :

Use pd.Index.difference:

df3 = df1.loc[df1.index.difference(df2.index)]
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