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

How do I match records from two different datasets using pandas?

I have got two dataframes of different shapes like:

Df1:

Index State city xyz
0 AL Ala .
1 CA . .
2 AK . .
3 AR . .
. . . .
. . . .

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

Index State Lat Long
0 AL 121 4456
1 AK 42 1266
2 AZ 1421 -426
3 AR 121 456
. . . .

I want to compare the State column in both the datasets and then for each state put the Lat and Long values for that state in the df1 frame. Something like this (using python, pandas and jupyter notebook):

Index State city xyz Lat Long
0 AL Ala . 121 4456
1 CA . . 198 4541
2 AK . . 42 1266
3 AR . . 121 456
. . . . ….

I have no Idea how to do this.
Thank you for reading this question, I am still a beginner, sorry if this is a stupid question.

>Solution :

Try this:

new_df = df1.merge(df2, on='State')
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