gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:49:09 24 4
gpt4 key购买 nike

我有两个数据框:

df1(索引为日期):

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

df2(索引为整数):

    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

我应该使用哪个函数?

最佳答案

添加并使用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

关于python - 合并具有不同索引的两个数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47946251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com