我想将pandas列中的列表与另一个普通列表进行比较,找到匹配值并将其放入另一列中。
我有一个术语列表,想查找是否有与特定单词匹配的词
| meta|
| --------------|
| ['Home',' grocery','cake']|
| ['Home',' grocery','Biscuit','Oreo']|
我正在从这个列表中查找匹配项:terms = ['cake','biscuit']
预期输出:
| meta|结果|匹配值|
| --------------|--------------|--------------|
| ['Home',' grocery','cake']|真的|['cake']|
| ['Home',' grocery','Biscuit','Oreo']|真的|['饼干']|
PS:我正在看如何获取match value列
3条答案
按热度按时间nwo49xxi1#
nafvub8i2#
你可以使用正则表达式模式在分解列表后提取子字符串:
输出:
q1qsirdb3#
我们使用带有矢量化字符串匹配的explode
为获得最佳结果,请确保
terms
中的术语也是小写的。让我们尝试另一组术语,看看这是如何工作的