1In [1]: df1 = pd.DataFrame(
2 ...: {
3 ...: "A": ["A0", "A1", "A2", "A3"],
4 ...: "B": ["B0", "B1", "B2", "B3"],
5 ...: "C": ["C0", "C1", "C2", "C3"],
6 ...: "D": ["D0", "D1", "D2", "D3"],
7 ...: },
8 ...: index=[0, 1, 2, 3],
9 ...: )
10
11In [8]: df4 = pd.DataFrame(
12 ...: {
13 ...: "B": ["B2", "B3", "B6", "B7"],
14 ...: "D": ["D2", "D3", "D6", "D7"],
15 ...: "F": ["F2", "F3", "F6", "F7"],
16 ...: },
17 ...: index=[2, 3, 6, 7],
18 ...: )
19 ...:
20
21In [9]: result = pd.concat([df1, df4], axis=1)
22# This will merge columns of both the dataframes
1In[17]:df['combined']=df['bar'].astype(str)+'_'+df['foo']+'_'+df['new']
2
3In[17]:df
4Out[18]:
5 bar foo new combined
60 1 a apple 1_a_apple
71 2 b banana 2_b_banana
82 3 c pear 3_c_pear
9