20

I have the following two data frames:

DF1: Id | field_A | field_B | field_C | field_D 1 | cat | 12 | black | 11 2 | dog | 128 | white | 19 3 | dog | 35 | yellow | 20 4 | dog | 21 | brown | 4 5 | bird | 10 | blue | 7 6 | cow | 99 | brown | 34 

and

DF2: Id | field_B | field_C | field_D | field_E 3 | 35 | yellow | 20 | 123 5 | 10 | blue | 7 | 454 6 | 99 | brown | 34 | 398 

And I am hoping to get the new_DF as

 Id | field_A | field_B | field_C | field_D | field_E 1 | cat | 12 | black | 11 | 2 | dog | 128 | white | 19 | 3 | dog | 35 | yellow | 20 | 123 4 | dog | 21 | brown | 4 | 5 | bird | 10 | blue | 7 | 454 6 | cow | 99 | brown | 34 | 398 

Could this be achieved by data frame operations? Thanks!

1 Answer 1

36

try this:

new_df = df1.join(df2, on=['field_B', 'field_C', 'field_D'], how='left_outer') 
Sign up to request clarification or add additional context in comments.

1 Comment

What will the code look if you need to join on ID and select either A or B field from either DF1 for DF2?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.