Hi everyone,
Could anyone help me out with this ValueError? I am doing a project for analyzing the type of posts that gets more comments on hacker news on the basis of the time. Here is the code:
import datetime as dt
result_list =
for row in ask_posts:
created_at = row[6]
result_list.append(created_at)
num_comments = int(row[4])
result_list.append(num_comments)
print(result_list[:10])
counts_by_hour = {}
comments_by_hour = {}
date_format = “%m/%d/%Y %H:%M”
for row in result_list:
date = row[0]
date = dt.datetime.strptime(date, date_format)
hour = date.strftime("%H")
if hour not in counts_by_hour:
counts_by_hour[hour] = 1
comments_by_hour[hour] = num_comments
else:
counts_by_hour[hour] += 1
comments_by_hour[hour] = num_comments
I am getting this error when I run it: (ValueError: time data ‘8’ does not match format ‘%m/%d/%Y %H:%M’
)
This is the first five datapoints of result_list: [‘8/16/2016 9:55’, 6, ‘11/22/2015 13:43’, 29, ‘5/2/2016 10:14’, 1, ‘8/2/2016 14:20’, 3, ‘10/15/2015 16:38’, 17]