-1

I have two dataframes that I'd like to merge:

df1=pd.DataFrame([['a','b','c'],['e','f','g'],['h','i','j']], columns=['X','Y','Z'], index=[10,15,25]) df2=pd.DataFrame([['A','B','C'],['H','I','J']], columns=['X','Y','Z'], index=[12,22]) #df1 X Y Z 10 a b c 15 e f g 25 h i j #df2 X Y Z 12 A B C 22 H I J 

I'd like to merge them sequentially, such that the rows in df2 are added to df1, on the same columns since columns would contain data from both.

# intended output X Y Z 10 a b c 12 A B C #from df2 15 e f g 22 H I J #from df2 25 h i j 
1
  • 2
    pd.concat([df1,df2], axis=0, sort=True) Commented Oct 26, 2020 at 13:34

1 Answer 1

1

Use df.append with sort_index():

In [2123]: df1.append(df2).sort_index() Out[2123]: X Y Z 10 a b c 12 A B C 15 e f g 22 H I J 25 h i j 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.