如何迭代一个dataframe列中的每个值并检查它是否包含另一个dataframe列中的单词?在
a = pd.DataFrame({'text': ['the cat jumped over the hat', 'the pope pulled on the rope', 'i lost my dog in the fog']})
b = pd.DataFrame({'dirty_words': ['cat', 'dog', 'parakeet']})
a
text
0 the cat jumped over the hat
1 the pope pulled on the rope
2 i lost my dog in the fog
b
dirty_words
0 cat
1 dog
2 parakeet
我想要一个只包含以下值的新数据帧:
^{pr2}$
使用与
str.contains
匹配的正则表达式。在单词边界确保不会仅仅因为“catch”包含“cat”就匹配它(谢谢@DSM)。在
我想你可以在^{之后使用
isin
在按空格拆分字符串后,可以将列表理解与
any
一起使用。这种方法不包括“导管”,因为它包括“猫”。在相关问题 更多 >
编程相关推荐