外部联接表 - 保留描述
new = pd.DataFrame({'table': \['a','b', 'c', 'd'\], 'desc': \['','','',''\], 'total':\[22,22,22,22\]})
old = pd.DataFrame({'table': \['a','b', 'e'\], 'desc': \['foo','foo','foo'\], 'total':\[11,11,11\]})
all = pd.merge(new, old, how='outer', on=\['table', 'total'\])
输出:
table desc_x total desc_y
0 a 22 NaN
1 b 22 NaN
2 c 22 NaN
3 d 22 NaN
4 a NaN 11 foo
所需的输出:
table desc total
0 a foo 22
1 b foo 22
2 c 22
3 d 22
4 a foo 11
我尝试进行外部连接,但它删除了A和B的描述。
new = pd.DataFrame({'table': \['a','b', 'c', 'd'\], 'desc': \['','','',''\], 'total':\[22,22,22,22\]})
old = pd.DataFrame({'table': \['a','b', 'e'\], 'desc': \['foo','foo','foo'\], 'total':\[11,11,11\]})
all = pd.merge(new, old, how='outer', on=\['table', 'total'\])
Output:
table desc_x total desc_y
0 a 22 NaN
1 b 22 NaN
2 c 22 NaN
3 d 22 NaN
4 a NaN 11 foo
Desired Output:
table desc total
0 a foo 22
1 b foo 22
2 c 22
3 d 22
4 a foo 11
I attempted to outer join, but it removed the descriptions of a and b.`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)