gpt4 book ai didi

python - 在 Pandas Python 中组合两个数据框

转载 作者:行者123 更新时间:2023-12-01 01:12:01 25 4
gpt4 key购买 nike

我想合并两个数据框

我想组合两个数据帧,使帐户相同。

例如,acct 10 应为 CME 和 NISSAN 中的值,而其余均为零。

最佳答案

我认为你可以使用 df.combine_first() :

It will update null elements with value in the same location in other.

df2.combine_first(df1)

此外,您可以尝试:

pd.concat([df1.set_index('acct'),df2.set_index('acct')],axis=1).reset_index()

关于python - 在 Pandas Python 中组合两个数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54759347/

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