0

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

1 Answer 1

1
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.