Reputation: 1070
I have 2 different dataframes.
group1
Gene Symbol
1 AA
2 BB
group2
Gene Symbol
1 XX
2 YY
3 ZZ
I want to merge this 2 dataframes in 1 column.
new = pd.DataFrame({'group1':group1['Gene Symbol'], 'group2':group2['Gene Symbol']})
I am able to merge dataframes but I couldn't combine columns like this.
group1 group2 total
1 AA XX AA
2 BB YY BB
3 ZZ XX
4 YY
5 ZZ
I have tried a lots of methods but I didn't find the solution.
Upvotes: 1
Views: 68
Reputation: 323226
concat
twice
df=pd.concat([pd.concat([df1,df2],ignore_index=True),
df1.reset_index(drop=True),
df2.reset_index(drop=True)],axis=1)
df.columns=['total','g1','g2']
df
Out[349]:
total g1 g2
0 AA AA XX
1 BB BB YY
2 XX NaN ZZ
3 YY NaN NaN
4 ZZ NaN NaN
Upvotes: 2