Concatenate pandas dataframes with different column names

0

I have two Pandas DataFrames that I would like to combine into one. They have the same number of columns, in the same order, but have headers with different names. Is there any approach to efficiently combining these dataframes?

df1
index  Data1   Nome1
0      1-1-18  1
1      2-1-18  2

df2
index  Data2   Nome2
0      3-1-18  3
1      4-1-18  4

df_concat
index  Data   Nome
0      1-1-18  1
1      2-1-18  2
2      3-1-18  3
3      4-1-18  4

The only approach I've found so far has been to rename the headers and then use the concat method:

pd.concat([df1, df2, axis = 0, ignore_index = True)

However, I would like to know if there is a more general approach.

    
asked by anonymous 31.01.2018 / 17:00

1 answer

2

I do not think it has anything more general, but I'd love to find an answer to that.

Looking at the Pandas Handbook on merging , Both concat and % with% create a copy.

You can use the

df1=df1.append(df2) 

But it will create an entire copy in memory to make append , such as append .

No SO has a question about this copy , where it is possible to use concat (or pd.merge(df1, df2, copy=False) ) when df1.merge(df2, copy=False) , but I could not solve your system with the merge as well.

    
31.01.2018 / 19:41