【发布时间】:2019-11-24 20:32:33
【问题描述】:
我有许多从 pdf 文件中读取的数据帧。它们看起来像这样:
e.g order 1 - this is a dataframe:
code description price quantity
000001 product A 1 10
000002 product B 2 20
000003 product C 3 30
...
order 2 - this is a dataframe:
code description price quantity
000001 product A 1 100
000002 product B 2 20
000004 product D 4 40
会有订单 3、4 等 我喜欢加入他们并按代码分组(这是唯一的)但显示 分开数量。
code description price order1 quantity order2 quantity
000001 product A 1 10 100
000002 product B 2 20 20
000003 product C 3 30 0
000004 product D 4 0 40
除了使用繁琐的循环之外,我想知道在 pandas 中是否有更简洁的方法来实现这一点。我以前在 excel vba 中使用丑陋的循环来处理这个,这是我第一次在 pandas 中尝试它。
非常感谢您的帮助!
【问题讨论】:
-
您需要连接并删除重复项。检查this
-
@shaikmoeed - 我认为 OP 还需要其他东西。