【发布时间】:2021-03-08 06:43:59
【问题描述】:
我有 2 个数据框,第一个是文本数据列(超过 10k 行),第二个是关键字(几乎 100 个列表)
数据帧 1:
Text
a white house cat plays in garden
cat is a domestic species of small carnivorous mammal
cat is walking in garden behind white house
yellow banana is healthy
数据帧 2:
ID Keywords
1 ['cat','white']
2 ['garden','white','cat']
3 ['domestic','mammal']
我想在数据框 1 中添加带有 ID 的列,其中最大字数与数据框 2 匹配。此外,如果超过 1 或 2 个 ID 之间存在联系,则将两个 ID 连接在一起。因此,在某些情况下,没有任何单词匹配,在这种情况下添加“不匹配”。
输出:
Text ID
a white house cat plays in garden 2
cat is a domestic species of small carnivorous mammal 3
cat is walking in behind white house 1,2
yellow banana is healthy 'No Match'
【问题讨论】:
标签: python-3.x pandas dataframe nlp keyword-search