通过精确的单词匹配过滤熊猫数据框

时间:2018-09-12 12:30:13

标签: python pandas

我想应用一个可以在文本中找到确切单词的函数。我有一个单词列表,我想在给定的文本中找到确切的单词。提供的代码与单词的字符匹配。我需要一个可以使用r匹配确切单词的解决方案。示例代码:

slno      comments
 1         Dear Customer, Thank you very much. We will get back soon with 
           analysis & rootcause by today. Regards, Amit
 2         Dear Customer, I will check and update you. Thanks, Rahul
 3         Hi Rick / Wei wang Will check the logs and update with the findings 
           Regards Satya
  4          Dear Customer, Thanks for opening the case. We will check and get 
            back to you soon. Thanks Harshit

匹配的单词应该是“谢谢”,“回来”,“问候”,“检查”,“更新”,“日志” wich记录与记录应放置的任何单词匹配,即使有一个应删除的单词也不匹配。

感谢前进

2 个答案:

答案 0 :(得分:0)

在Python中,我将拆分注释,并将拆分后的注释中的每个单词与要匹配的单词列表进行比较。

可以执行以下操作:

word in comment.split(' ')

答案 1 :(得分:0)

问题还不够清楚。

如果我理解正确:

def lookup(tempDf, tempWord ):
    for i in range(NumberOfRows):
       if tempWord in tempDf.iloc[i]:
          tempDf.drop(tempDf.drop(tempDf.index[i]), inplace=True)
    return tempDf

wordsList = ['Thank', 'get back', 'Regard', 'check', 'update', 'logs']

for word in wordsList:
    df = lookup(df, word)
相关问题