【发布时间】:2017-11-30 14:05:36
【问题描述】:
我对 pandas 数据框很陌生,我在连接两个表时遇到了一些麻烦。
第一个 df 只有 3 列:
DF1:
item_id position document_id
336 1 10
337 2 10
338 3 10
1001 1 11
1002 2 11
1003 3 11
38 10 146
第二个有完全相同的两列(还有很多其他列):
DF2
item_id document_id col1 col2 col3 ...
337 10 ... ... ...
1002 11 ... ... ...
1003 11 ... ... ...
我需要执行的操作在 SQL 中如下所示:
DF1 join DF2 on
DF1.document_id = DF2.document_id
and
DF1.item_id = DF2.item_id
因此,我希望看到 DF2,并辅以“位置”列:
item_id document_id position col1 col2 col3 ...
什么是使用 pandas 的好方法?
谢谢!
【问题讨论】:
标签: python mysql sql pandas dataframe