0

I have two dataframes:

df1:

name surname
jane doe
john doe

df2

name
james

I want to add df2 to df1:

df_final

name    surname 
james   doe
jane    doe
john

with df1.add(df2) I haven't correct result. how can I add df2's data to first column of df1?

1 Answer 1

1

Use append to do that i.e

df2.append(df1)

Output :

  name surname
0  james     NaN
0   jane     doe
1   john     doe

For your expected output you can do

df2.append(df).apply(sorted,key=pd.isnull).fillna('')
  name surname
0  james     doe
0   jane     doe
1   john        
Sign up to request clarification or add additional context in comments.

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.