如何在python中具有完整段落的列的多行上使用datefinder

如何在python中具有完整段落的列的多行上使用datefinder,python,python-3.x,Python,Python 3.x,我有一个包含2列计数器和历史记录的数据框,如下所示 *counter History* 1 Log Type: customer chat chat history: xxxxxxxxx xxxxxxx xxxxxxxxxxxxxxx May 10 2020 23:34:57 +GMT 05:30 ------------------------

我有一个包含2列计数器和历史记录的数据框,如下所示

*counter History*
1        Log Type: customer chat
         chat history:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
              eeeeeeeeeeeeee
              eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
              eeeeeeee
              eeeeeeeeeee
              eeeeeeeeeeee
              eeeeeeeeeeeeeeeeeee
              May 11 2020 14:58:54 + GMT 05:30
            ----------------------------------
2           Log Type: Phone call
            issue:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
               eeeeeeeeeeeeee
               eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
               eeeeeeee
               eeeeeeeeeee
               eeeeeeeeeeee
               eeeeeeeeeeeeeeeeeee
             May 12 2020 14:58:54 + GMT 05:30
            ----------------------------------------------
counter History                                                 count
0        Log Type: customer chat                                 1
         chat history:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
              eeeeeeeeeeeeee
              eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
              eeeeeeee
              eeeeeeeeeee
              eeeeeeeeeeee
              eeeeeeeeeeeeeeeeeee
              May 11 2020 14:58:54 + GMT 05:30
            ----------------------------------
1           Log Type: Phone call                                3
            issue:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
               eeeeeeeeeeeeee
               eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
               eeeeeeee
               eeeeeeeeeee
               eeeeeeeeeeee
               eeeeeeeeeeeeeeeeeee
             May 12 2020 14:58:54 + GMT 05:30
            ----------------------------------------------
TypeError: can't compare offset-naive and offset-aware datetimes
现在,我想做一个检查,如果日志类型为“仅电话呼叫”,则应计算唯一的日期戳,即如果两个日期戳相同,则计数应为1个时间戳,在这种情况下,不需要。 下面给出了所需的输出

*counter History*
1        Log Type: customer chat
         chat history:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
              eeeeeeeeeeeeee
              eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
              eeeeeeee
              eeeeeeeeeee
              eeeeeeeeeeee
              eeeeeeeeeeeeeeeeeee
              May 11 2020 14:58:54 + GMT 05:30
            ----------------------------------
2           Log Type: Phone call
            issue:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
               eeeeeeeeeeeeee
               eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
               eeeeeeee
               eeeeeeeeeee
               eeeeeeeeeeee
               eeeeeeeeeeeeeeeeeee
             May 12 2020 14:58:54 + GMT 05:30
            ----------------------------------------------
counter History                                                 count
0        Log Type: customer chat                                 1
         chat history:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
              eeeeeeeeeeeeee
              eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
              eeeeeeee
              eeeeeeeeeee
              eeeeeeeeeeee
              eeeeeeeeeeeeeeeeeee
              May 11 2020 14:58:54 + GMT 05:30
            ----------------------------------
1           Log Type: Phone call                                3
            issue:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
               eeeeeeeeeeeeee
               eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
               eeeeeeee
               eeeeeeeeeee
               eeeeeeeeeeee
               eeeeeeeeeeeeeeeeeee
             May 12 2020 14:58:54 + GMT 05:30
            ----------------------------------------------
TypeError: can't compare offset-naive and offset-aware datetimes
我用的代码是

import datetime
from dateparser.search import search_dates
def extract_sentence(input, word):
    return ".".join((sentence for sentence in input.split("----") if word in sentence))
df2.reset_index(inplace=True)
lst_3=[]
ind_1=[]
for i in range (0,len(df2('counter'):
    matches = search_dates(extract_sentence(df2['History'][i],'Phone call'))
    lst_4=[]
    for x in matches:
        date_string =  x[1]
        lst_4.append(date_string)
    lst_6=[]
    lst_5=[]
    for item in lst_4:
        lst_5.append(str(item))
    for i in lst_5:
        ab=i[0:10]
        lst_6.append(ab)
    res = [i for i in lst_6 if '2020' in i or '2019' in i or '2018' in i or '2017' in i or '2016' in i or '2015' in i]
    lst_8=[]
    lst_8=len(list(set(res)))
    lst_1=[]
    try:
        for match in matches:
            lst=match
            lst_1.append(lst)
    except TypeError:
        continue
    ind=i
    ind_1.append(ind)
    lst_2=len(list(set(lst_1)))
    lst_3.append(lst_2)
                
df3=pd.DataFrame({'Index1': ind_1,'Count3': lst_3})

df2.reset_index(inplace=True)
df2['Index1']= np.arange(len(df2))

df4=pd.merge(df2,df3[['Index1','Count3']],on='Index1',how='left')
下面给出了我运行此程序时遇到的错误

*counter History*
1        Log Type: customer chat
         chat history:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
              eeeeeeeeeeeeee
              eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
              eeeeeeee
              eeeeeeeeeee
              eeeeeeeeeeee
              eeeeeeeeeeeeeeeeeee
              May 11 2020 14:58:54 + GMT 05:30
            ----------------------------------
2           Log Type: Phone call
            issue:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
               eeeeeeeeeeeeee
               eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
               eeeeeeee
               eeeeeeeeeee
               eeeeeeeeeeee
               eeeeeeeeeeeeeeeeeee
             May 12 2020 14:58:54 + GMT 05:30
            ----------------------------------------------
counter History                                                 count
0        Log Type: customer chat                                 1
         chat history:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
              eeeeeeeeeeeeee
              eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
              eeeeeeee
              eeeeeeeeeee
              eeeeeeeeeeee
              eeeeeeeeeeeeeeeeeee
              May 11 2020 14:58:54 + GMT 05:30
            ----------------------------------
1           Log Type: Phone call                                3
            issue:
            xxxxxxxxx
            xxxxxxx
            xxxxxxxxxxxxxxx
            May 10 2020 23:34:57 +GMT 05:30
            --------------------------------------------
            log type: Phone call
            issue type: xxxxxx
            issue:
             qqqqqqqqqqqq
             qqqqqqqqqqqqqqqqqqqqqqq
             qqqqqqqqqqqqqqq
             May 11 2020 08:54:54 + GMT 05:30
             ----------------------------------------------
             log type: phone call
             issue:
               eeeeeeeeeeeeee
               eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
               eeeeeeee
               eeeeeeeeeee
               eeeeeeeeeeee
               eeeeeeeeeeeeeeeeeee
             May 12 2020 14:58:54 + GMT 05:30
            ----------------------------------------------
TypeError: can't compare offset-naive and offset-aware datetimes

需要这方面的帮助

我知道你想做什么,但是你的代码很难读,我不理解lst\u X变量。错误是在哪一行触发的?我在``matches=search\u日期上得到错误(摘录句子(df6['Case\u History'][I],'Phone Log'))```请更新您的原始帖子以添加信息。是否查看了
匹配项中的内容?因为我对您的数据应用了
search\u dates
,它返回3个datetime对象:一个用于“2020年5月11日”,一个用于“08:54:54+GMT”,另一个用于“05:30”。因此,发生错误似乎是合理的。