2 回答
TA贡献1883条经验 获得超3个赞
尝试这个:
keywords = [
"i can help you with that",
"i can surely help you with that",
"i can check and help you with that",
"i will be more than happy to help you",
"let me assist you on this",
"to assist you better"
]
for phrase in keywords:
for row in col1:
if phrase in row.lower():
return row
所以这是在做的是查看你的 excel 表的列......
col1
1 Hello and welcome
2 There's a lot to see here
3 Sorry, no can do
4 I can help you with that if you'd like
并一一浏览它们。如果其中一行包含您的关键短语...
>I can help you with that< if you'd like
它会返回整行。您可以打印而不是返回或任何您想要对行执行的操作。.lower() 方法是因为我们的关键字以小写形式存储,因此应该将它们与行的小写版本进行比较。如果匹配,我们可以返回原始情况下的行。当然,我假设您已经成功地将您的数据导入 col1 中,就像某种列表一样……如果您需要帮助,请告诉我。
TA贡献1111条经验 获得超0个赞
我认为这会有所帮助
import re
keywords=[
"i can help you with that",
"i can surely help you with that",
"i can check and help you with that",
"i will be more than happy to help you",
"let me assist you on this", "to assist you better",
]
file_contents = '' # here is where you get contents from excel file
for line in file_contents:
for keyword in keywords:
temp = re.search(r''+ keyword +'', line, flags=re.IGNORECASE)
if temp:
print('[out]:', line)
添加回答
举报