【发布时间】:2017-04-02 22:40:15
【问题描述】:
我有两个数据框
(1st Dataframe)
**Sentences**
hello world
live in the world
haystack in the needle
(2nd Dataframe in descending order by Weight)
**Words** **Weight**
world 80
hello 60
haystack 40
needle 20
如果句子中的任何单词包含第二个数据帧中列出的单词,我想检查第一个数据帧中的每个句子,并选择权重最高的单词。然后,我将找到的最高权重词分配给第一个数据帧。所以结果应该是:
**Sentence** **Assigned Word**
hello world world
live in the world world
needle in the haystack haystack
我曾想过使用两个 for 循环,但如果有数百万个句子或单词,性能可能会很慢。在 python 中执行此操作的最佳方法是什么?谢谢!
【问题讨论】: