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

Merge and match using Pandas

I would like to Merge and match using Pandas

Data

df1

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

ID      name    stat    
aa678   TRUE    112 
aa678   FALSE   111 
bb131   TRUE    122 
        

df2

ID2     Box
aa678   santa fe
cc121   delux

Desired

ID      name    stat    Box
aa678   TRUE    112     santa fe
aa678   FALSE   111     santa fe
bb131   TRUE    122 
        

Doing

df1.join(df2.set_index('ID'), on = 'ID2')

However, this is not giving the desired result and not showing the values that do not have matches.

Any suggestion is appreciated.

>Solution :

Use merge which does the same thing but offers more flexibility:

df1.merge(df2, left_on="ID", right_on="ID2", how="left")
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