【发布时间】:2015-02-17 19:38:51
【问题描述】:
我有 2 个数据框:
df1 有白色产品的 ID 和计数
product_id, count_white
12345,4
23456,7
34567,1
df2 有所有产品的 ID 和计数
product_id,total_count
0009878,14
7862345,20
12345,10
456346,40
23456,30
0987352,10
34567,90
df2 的产品比 df1 多。我需要在 df2 中搜索 df1 中的产品并将 total_count 列添加到 df1:
product_id,count_white,total_count
12345,4,10
23456,7,30
34567,1,90
我可以进行左合并,但我最终会得到一个巨大的文件。有没有办法使用合并将特定行从 df2 添加到 df1?
【问题讨论】:
-
不清楚为什么你认为左合并会产生一个巨大的文件,通过对产品 id 执行左合并你说你只对 product_id 列中的匹配感兴趣