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 to merge in pandas with 4 columns

I have 2 Dataframe in pandas. I want to merge but, I need to do it by 4 columns. Somenthing like that:

DF 1:

doc, cod_doc, name, city

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

DF 2:

id, cod_id, income

I need doing merge for doc = id and cod_doc = cod_id.

This is my code:

f = pd.merge(customers_adress, customers_income,left_on='doc',right_on='id',how='left') 

>Solution :

you can merge on multiple columns, sounds like you want to do

df = pd.merge(customers_adress, customers_income,left_on=['doc','cod_doc'],right_on=['id','cod_id'],how='left')

without having your dfs it is hard to say if this is exactly what you want but it should work

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