1

hello i'm newbie in pandas

for example, datas of cryptocurrency are as below

BTC

time(index) open high low close value
0           1     4    1    2     1
1           2     5    2    3     2

ETH

time(index) open high low close value
1           1     1    1    1     1

and I want merge these datas as blow

BTC X ETH

                      BTC                        ETH
time(index) open high low close value  open high low close value
0           1     4    1    2     1    NaN  NaN  NaN  NaN   NaN
1           2     5    2    3     2     1    1    1    1     1

is there any way to merge?

1 Answer 1

2

Use concat with parameter keys for first level of MultiIndex:

df = pd.concat([df1, df2], keys=('BTC','ETH'), axis=1)
print (df)
             BTC                       ETH                      
            open high low close value open high  low close value
time(index)                                                     
0              1    4   1     2     1  NaN  NaN  NaN   NaN   NaN
1              2    5   2     3     2  1.0  1.0  1.0   1.0   1.0
Sign up to request clarification or add additional context in comments.

Comments

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.