按列集合合两个DataFrame

时间:2014-05-24 15:47:25

标签: python pandas

我有两个Pandas DataFrames:

df1

name_tokens
[havard, university, kennedy school, government]
[university, texas, austin]
[boston, college] 

df2

ranking    name_tokens
  1        [havard, university]
  2        [university, texas]
  3        [boston, college] 

我想在df2之前将df1合并到name_tokens以获取ranking。合并条件是:

(df1['name_tokens'] & df2['name_tokens']) == df2['name_tokens']

我应该如何自定义合并方法来完成此操作? (我在df1中有数百万条记录,并且它可以是多对一合并到df2,因此需要快速实现。

0 个答案:

没有答案