猿问

提取包含关键字的行

修改问题,每当col1有关键字时,我想提取col2中的时间戳


关键字=[“我可以帮助你”,“我肯定可以帮助你”,“我可以检查并帮助你”,“我会非常乐意帮助你”,“让我帮助你在这方面”,“更好地帮助您”]


鉴于excel数据是,


    col1                                                                                                                            

1.agent enters(as arrin)

2.

3.I'll be happy to assist you. Give me a moment to review your request.

4.I see that the light in your Modem is Blinking Red. Am I right ?

5.Thank you for the detailed information.

6.Please do not worry.

7.Don't worry johny. I can help you with that.

8.Let me connect this chat to the concern team to help you out with this, 

  Please stay connected.


   col2

1. 2018-10-14 21:16:58

2. 2018-10-14 21:17:00

3. 2018-10-14 21:17:40

4. 2018-10-14 21:18:25

5. 2018-10-14 21:19:39

6. 2018-10-14 21:19:43

7. 2018-10-14 21:21:04

8. 2018-10-14 21:22:00

例如关键字之一出现在第 7 行,因此要提取 col2 中的相应时间戳


所需的输出应如下所示,


[出]:2018-10-14 21:21:04


提前致谢


慕桂英546537
浏览 178回答 2
2回答

白板的微信

尝试这个:keywords = [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "i can help you with that",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "i can surely help you with that",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "i can check and help you with that",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "i will be more than happy to help you",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "let me assist you on this",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "to assist you better"]for phrase in keywords:&nbsp; &nbsp; for row in col1:&nbsp; &nbsp; &nbsp; &nbsp; if phrase in row.lower():&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return row所以这是在做的是查看你的 excel 表的列......&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; col11 Hello and welcome2 There's a lot to see here3 Sorry, no can do4 I can help you with that if you'd like并一一浏览它们。如果其中一行包含您的关键短语...>I can help you with that< if you'd like它会返回整行。您可以打印而不是返回或任何您想要对行执行的操作。.lower() 方法是因为我们的关键字以小写形式存储,因此应该将它们与行的小写版本进行比较。如果匹配,我们可以返回原始情况下的行。当然,我假设您已经成功地将您的数据导入 col1 中,就像某种列表一样……如果您需要帮助,请告诉我。

catspeake

我认为这会有所帮助import rekeywords=[&nbsp; &nbsp; "i can help you with that",&nbsp;&nbsp; &nbsp; "i can surely help you with that",&nbsp;&nbsp; &nbsp; "i can check and help you with that",&nbsp;&nbsp; &nbsp; "i will be more than happy to help you",&nbsp;&nbsp; &nbsp; "let me assist you on this", "to assist you better",]file_contents = '' # here is where you get contents from excel filefor line in file_contents:&nbsp; &nbsp; for keyword in keywords:&nbsp; &nbsp; &nbsp; &nbsp; temp = re.search(r''+ keyword +'', line, flags=re.IGNORECASE)&nbsp; &nbsp; &nbsp; &nbsp; if temp:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('[out]:',&nbsp; line)
随时随地看视频慕课网APP

相关分类

Python
我要回答