小编L-s*_*are的帖子

两个 DataFrame 的复杂合并

我有两个数据帧:

df1:

                     top1 top2 top3
693541495124446625    US   GB   CN
912819499544441670    US   CN   TW
Run Code Online (Sandbox Code Playgroud)

df2:

                         US   GB    CN    TW  \ ...
                                                                    
693541495124446625  939.00 932.00 806.00 789.00 ...
912819499544441670  992.00 646.00 981.00 796.00 ...
Run Code Online (Sandbox Code Playgroud)

如何合并或迭代两个数据帧以获得以下结果:

                       top1          top2          top3
693541495124446625    'US 939.00'  'GB 932.00'   'CN 806.00'
912819499544441670    'US 992.00'  'CN 981.00'   'TW 796.00'
Run Code Online (Sandbox Code Playgroud)

我知道我可以迭代取 df1 值并[loc]通过几个 for 循环将该值作为列放在 df2 中,但是有没有优化的解决方案?

python merge dataframe pandas

4
推荐指数
1
解决办法
52
查看次数

标签 统计

dataframe ×1

merge ×1

pandas ×1

python ×1