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
它會返回整行。您可以打印而不是返回或任何您想要對行執(zhí)行的操作。.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)
添加回答
舉報