Boosted_d16
Boosted_d16

Reputation: 14112

pandas python: concet/merge/join 2 dfs on index

I have two dfs which I would like to concat on index to make a multiindex df.

df1 = pd.DataFrame({'value1': [1.1,2,3],
                    })

df2 = pd.DataFrame({'value1': [21,24,35],
                    })

Expected output

    value1
0      1.1
       21
1      2.0
       24
2      3.0
       35
3      4.0

my failed attempt:

df = pd.concat([df1, df2], axis=0)

output

   value1
0     1.1
1     2.0
2     3.0
0    21.0
1    24.0
2    35.0

Upvotes: 0

Views: 670

Answers (1)

unutbu
unutbu

Reputation: 880219

In [57]: pd.concat([df1, df2], axis=0).sort_index()
Out[57]: 
   value1
0     1.1
0    21.0
1     2.0
1    24.0
2     3.0
2    35.0

Upvotes: 1

Related Questions