1

I have 2 dataframes df1 and df2

df1

Col1   Col2   Col3  Col4 

df2

Key_col   Col5   Col6   Col7

So i need only the Key_col from second dataframe when I combine the two dataframes.

pd.merge(f1, df2, how='outer')

This gives all columns from both dataframes

Expected output

Col1   Col2   Col3  Col4 Key_col
noob
  • 3,601
  • 6
  • 27
  • 73

1 Answers1

2

Try this:

df1 = pd.DataFrame( data=[ [1,2,4], [2,336,6], [343,44,7]], columns=['Col1', 'Col2', 'Col3'])
df2 = pd.DataFrame( data=[ [1,2,45], [2,33,56], [343,44,67]], columns=['Key_Col', 'Col4', 'Col5'])

concated_df = pd.concat([df1,df2['Key_Col']], axis=1)
print(concated_df)

Results into:

   Col1  Col2  Col3  Key_Col
0     1     2     4        1
1     2   336     6        2
2   343    44     7      343
vbn
  • 274
  • 2
  • 7