pandas to_datetime() then concat() on DateTime Index

后端 未结 2 1057
囚心锁ツ
囚心锁ツ 2021-01-19 04:32

I\'m trying to merge 2 DataFrames using concat, on their DateTime Index, but it\'s not working as I expected. I copied some of this code from the example in the

相关标签:
2条回答
  • 2021-01-19 04:36

    You need axis=1:

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

    Output:

                value    0
    2015-02-04    444  222
    2016-03-05    555  333
    
    0 讨论(0)
  • 2021-01-19 04:45

    pass axis=1 to concatenate column-wise:

    In [7]:
    pd.concat([df,df2], axis=1)
    
    Out[7]:
                value    0
    2015-02-04    444  222
    2016-03-05    555  333
    

    Alternatively you could've joined:

    In [5]:
    df.join(df2)
    
    Out[5]:
                value    0
    2015-02-04    444  222
    2016-03-05    555  333
    

    or merged:

    In [8]:
    df.merge(df2, left_index=True, right_index=True)
    
    Out[8]:
                value    0
    2015-02-04    444  222
    2016-03-05    555  333
    
    0 讨论(0)
提交回复
热议问题