我有两个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
,因此需要快速实现。