0

我一直在尝试从whatsapp群聊.txt (复制这个)制作一个DataFrame,但我似乎无法让它工作,解析的列表应该在.txt拥有但总是出来的每一行不管我做什么都是空的,不知道问题出在哪里。这个块是错误的,所以它永远不会填满列表,或者这很好并且代码的其他部分是错误的?

> parsed = [] 
> path = '_chat.txt'
> with open(path, encoding="utf-8") as fp:
>     fp.readline()
>     msg_buffer = []
>     date, time, author = None, None, None
>     while True:
>         line = fp.readline()
>         if not line:
>             break
>         line = line.strip()
>         if starts_with_date_time(line):
>             if len(msg_buffer) > 0:
>                 parsed.append([date, time, author, ' '.join(msg_buffer)])
>             msg_buffer.clear()
>             date, time, author, message = get_data_point(line)
>             msg_buffer.append(message)
>         else:
>             msg_buffer.append(line)
> df = pd.DataFrame(parsed, columns=['date', 'time', 'author', 'message'])
4

0 回答 0