Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Merge two different dataframes

I want to merge two different dataframe which the second one has some rows to complete in the first one.

df4 = pd.DataFrame({'a':['red','green','yellow','blue'],'b':[1,5,6,7],'c':[1,7,8,9]})
df5 = pd.DataFrame({'a':'red','b':44, 'c':55}, index=[0])
print(pd.merge(df4,df5, how='left', on='a'))

Output


     a    b_x   c_x  b_y    c_y
0   red     1   1   44.0    55.0
1   green   5   7   NaN NaN
2   yellow  6   8   NaN NaN
3   blue    7   9   NaN NaN

Expected Output


    a      b    c
0   red    44   55
1   green   5   7
2   yellow  6   8
3   blue    7   9
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Replace - with np.nan and use combine_first:

df4.replace('-',np.nan,inplace=True)
df4.combine_first(df5)

prints:

        a     b     c
0     red  44.0  55.0
1   green   5.0   7.0
2  yellow   6.0   8.0
3    blue   7.0   9.0
over 4 years ago · Santiago Trujillo Report

0

Concatenate and drop duplicates by column 'a'.

print(pd.concat([df5, df4]).drop_duplicates(['a'], keep='first'))
over 4 years ago · Santiago Trujillo Report

0

You can use DataFrame.update:

df4.update(df5)

Output:

>>> df4
        a     b     c
0     red  44.0  55.0
1   green     5     7
2  yellow     6     8
3    blue     7     9
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!