Bendaa
Bendaa

Reputation: 1

ValueError: time data '11/25/20, 5:08:34 PM' does not match format '-%m/-%d/-%y, -%I:%M:%S %p'

im trying to extract data from a whatsapp group for analyzation; creating heatmaps of activity as a function of weekdays (x axis) and 2 hour time windows (y axis),

I figured my first step should be to make a dictionary for each message, having the keys as the date of message, and the value being the message itself. i tried using strptime function to convert the the dates from strings. ive been stuck for hours trying to figure out what im doing wrong here:

import datetime

with open('chat.txt','r+', encoding='utf-8') as f:
    content = f.readlines()

dict = {}

for line in content:
    line = line.replace('[','')
    line = line.replace(']',')')
    line = line.replace('\u200e', '')
    line = line.partition(')')
    dict[key] =  datetime.datetime.strptime(line[0], '-%m/-%d/-%y, -%I:%M:%S %p')
    
    






    
       
      


 

Upvotes: 0

Views: 110

Answers (1)

Kris
Kris

Reputation: 8868

Your date format is wrong. I can see additional - separators in your format. Remove that and all will work fine.

Your example in right way below:

datetime.datetime.strptime('11/25/20, 5:08:34 PM', '%m/%d/%y, %I:%M:%S %p')

will generate the output

datetime.datetime(2020, 11, 25, 17, 8, 34)

Upvotes: 1

Related Questions