关于pandas:Python用一个公共列将两个框架连接起来

Python join two frames with one common column

我在python框架A中有

enterA['b']和B['v']

我正在尝试使用pandas concat或merge,但是我失败了。

我在框架A中的预期结果是:

enter


合并失败了吗?它应该在left与A相连的连接上工作,并指定left_onright_on列:

1
final_output = A.merge(B,how='left',left_on='b',right_on='v').rename(columns={'z':'name'}).drop(columns='v')

输出:

1
2
3
4
5
     a  b    c     d   name
0  Yes  1  Yes   Buy  name1
1  Yes  2  Yes  Sell  name2
2  Yes  3  Yes   Buy  name3
3  Yes  4  Yes  Sell  name4