合并具有不同索引的两个数据帧

时间:2017-12-22 19:09:40

标签: python pandas

我有两个数据帧:

df1(索引是日期):

             a  b
1900-01-01   1  2
1900-01-02   1  3
1900-01-03   3  3

df2(index is int):

    c
0   3 
1   1
合并后

             a  b  d
1900-01-01   1  2  3
1900-01-02   1  3  1
1900-01-03   3  3

我应该使用哪种功能?

1 个答案:

答案 0 :(得分:3)

添加values并使用at

df1.at[:len(df2),'d']=df2.c.values
df1
Out[1200]: 
            a  b    d
1900-01-01  1  2  3.0
1900-01-02  1  3  1.0
1900-01-03  3  3  NaN
相关问题