在每个时间戳上分割注释

问题描述 投票:0回答:1

嘿,我在一个单元格中有各种时间戳的注释,如下所示:-

2019-07-26 20:36:19-(工作说明)通知呼叫者交易已从Concur中删除。解决了INC,因为没有待处理的操作。发送解决方案电子邮件给呼叫者,复制粘贴回复并简化/总结从Eng团队收到的信息是更新工作说明是将状态更新为“正在等待用户”是

2019-07-26 10:32:05-oneflow(工作说明)[code]嗨,团队。我们已经删除了这些gits。

我想要的是将此单元格拆分为行,以便每个时间戳都以其各自的文本拆分

请帮助。 R或Python中的任何代码都会有所帮助。

r datetime text split comments
1个回答
0
投票

使用regex的Python选项:

import re
from datetime import datetime

s = """2019-07-26 20:36:19 - (Work notes) Informed the caller that the [...]
line without timestamp!
2019-07-26 10:32:05 - oneflow (Work notes)[code] Hi Team.We have removed those gits."""

ts_txt = []
for l in s.splitlines():
    t = re.search(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}', l)
    if t:
        ts_txt.append([datetime.strptime(t.group(0), '%Y-%m-%d %H:%M:%S'), l[t.end():]])

# ts_txt
# [(datetime.datetime(2019, 7, 26, 20, 36, 19),
#   ' - (Work notes) Informed the caller that the [...]'),
#  (datetime.datetime(2019, 7, 26, 10, 32, 5),
#   ' - oneflow (Work notes)[code] Hi Team.We have removed those gits.')]

在此示例中,您将获得一个元组列表,其中包含时间戳记作为日期时间对象和相应的字符串。如果一行没有时间戳,它将不会进入输出。

© www.soinside.com 2019 - 2024. All rights reserved.