Python join two frames with one common column
我在python框架A中有
和框B:
如何在框架A中添加新列"名称",以显示框架b中的z列值?两个帧之间的公共列是
我正在尝试使用pandas concat或merge,但是我失败了。
我在框架A中的预期结果是:
非常感谢。
此致
吉安卡洛
合并失败了吗?它应该在
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 |