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

Why do I have more row after the left merge and drop_duplciates()?

iso_selected.shape gives the result: (257, 2)

gravity.shapegives the result: (4428288, 79)

and I merge them in the following way:

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

gravity1 = gravity.merge(iso_selected, how="left", left_on = "iso3_o", right_on="iso3").drop_duplicates()

gravity1.shape gives the result: (4571136, 81)

Why would I have more rows than 4428288 ?

>Solution :

You need remove duplicates before DataFrame.merge by column iso3_o:

gravity1 = gravity.merge(iso_selected.drop_duplicates(subset=["iso3_o"]), 
                         how="left", 
                         on = "iso3_o")
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