0

I have multiple Pandas Dataframes, all of them have the same column names but in different sequence for example:

   df_1:

    X   Y   Z   
    5   4   3   

   df_2:

    Z   X   Y
    5   4   4

How to merge them by column name? I want my output look like this:

   df_3:

    X   Y   Z   
    5   4   3 
    4   4   5  
Aly
  • 347
  • 3
  • 13

1 Answers1

2

Use pandas.DataFrame.append, it automatically takes care of column alignments:

>>> df.append(df2, ignore_index=True)
   X  Y  Z
0  5  4  3
1  4  4  5
Sayandip Dutta
  • 15,602
  • 4
  • 23
  • 52