1

I have df1

index   state   fin_salary  new_title
5         CA      1          Data Scientist
8         CA      1          Data Scientist
35        CA    150000       Deep Learning Engineer
36        CA    1            Data Analyst
39        CA    1            Data Engineer
43        CA    1            Data Scientist
56        CA    1            Data Scientist

And another datfarame df2

state   new_title                     fin_salary
CA  Artificial Intelligence Engineer    207500.0
CA  Data Analyst                       64729.0
CA  Data Engineer                      146000.0
CA  Data Scientist                     129092.75
CA  Deep Learning Engineer             162500.0
CA  Machine Learning Engineer          133120.0
CA  Python Developer                   96797.0

So I want to update df1 with fin_salary from df2 based on condition state and new_title and where fin_salary = 1. So my desired output should be

index   state   fin_salary           new_title
5         CA      129092.75         Data Scientist
8         CA      129092.75         Data Scientist
35        CA    150000              Deep Learning Engineer
36        CA    64729.0             Data Analyst
39        CA    146000.0             Data Engineer
43        CA    129092.75            Data Scientist
56        CA    129092.75            Data Scientist

1 Answer 1

1

You can do this:

DF = df1.merge(df2, on=['state','new_title'], how = 'inner')

df_final = DF[DF['fin_salary']==1]
Sign up to request clarification or add additional context in comments.

2 Comments

Yes it helped. I tweaked a bit more to get my desired result. Thanks a lot.
Glad it helped! Happy coding! And welcome to SO!

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.