0

Given 2 data frames like the link example, I need to add to df1 the "index income" from df2. I need to search by the df1 combined key in df2 and if there is a match return the value into a new column in df1. There is not an equal number of instances in df1 and df2 and there are about 700 rows in df1 1000 rows in df2.

I was able to do this in excel with a vlookup but I am trying to apply it to python code now.

Data Frame images

2 Answers 2

1

This should solve your issue:

df1.merge(df2, how='left', on='combind_key')

This (left join) will give you all the records of df1 and matching records from df2.

Sign up to request clarification or add additional context in comments.

Comments

0

https://www.geeksforgeeks.org/how-to-do-a-vlookup-in-python-using-pandas/

Here is an answer using joins. I modified my df2 to only include useful columns then used pandas left join.

Left_join = pd.merge(df,  
                     zip_df,  
                     on ='State County',  
                     how ='left') 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.