Dont understand the if statement when calculated the avg comment by hour

HI! I dont understand the if statement below,could you help? Why we need to create 2 dictionaries? and why we put comments_by_hour[hour]=comment and comments_by_hour[hour] +=comment? After i run these codes, 2 dictionary has different output, for example, at 17:00, one has frequency 100 another has frequency 1146.
Thank you so much!

counts_by_hour={}
comments_by_hour={}
date_format = “%m/%d/%Y %H:%M”
for row in result_list:
date=row[0]
comment=row[1]
dateformat=dt.datetime.strptime(date,date_format)
hour=dt.datetime.strftime(dateformat,"%H") #extract hour
if hour not in counts_by_hour:
counts_by_hour[hour]=1
comments_by_hour[hour]=comment
else:
counts_by_hour[hour]+=1
comments_by_hour[hour] +=comment
print(counts_by_hour)
print(’\n’)
print(comments_by_hour)

Hi! As far as I remember the project, the dictionary counts_by_hour keeps the number of posts published each hour and the comments_by_hour keeps the total number of comments which all the post published at same hour receive.