Yeah, in the solution: your number of posts and comments created in a certain time by hour is

found by using for loop to get comments per hour, then you calculate (1)the Amount* of HN Ask Posts (equiv = total/sum of those comments per hour), (2)the average of HN ASK comments (avg_by_hour*) and then swap* avg_by_hour and finally print! However through this route you first have to import datetime. I hope you understand this explanation. Did you try to add the num_comments in your Output [36], to get the Amount/total Amount and calculate avg_by_hour?

Hi @OlutokiJohn,

I managed to get you answers for your dataflow/or your project’s answers are OK (Remember not to forget to insert that function hn.shape = hacker_news.shape between your header and describe), Now you need to do the following last 4 block of codes per cell/i.e., markdown code 37, 38, 39 and 40 then Run these cells):

In[37]

max_by_comments = 0

max_comments = [ ]

for row in comments_by_hour:

if comments_by_hour[row] > max_by_comments:

max_by_comments = comments_by_hour[row]

max_comments = [row, comments_by_hour[row]]

print('With ’ + str(max_comments[1]) + ’ most of the comments were written around ’ + str(max_comments[0]) + " o’clock.")

In[38]

avg_by_hour = [ ]

for hour in counts_by_hour:

avg = comments_by_hour[hour] / counts_by_hour[hour]

avg_by_hour.append([hour, avg])

for row in sorted(avg_by_hour):

print('Hour: ’ + str(row[0]) + ’ Comments (avg): ’ + str(row[1]))

In[39]

swap_avg_by_hour = [ ]

for row in avg_by_hour:

swap_avg_by_hour.append([row[1], row[0]]) # here we swap the index of the row and append it the new list

print(swap_avg_by_hour)

In[40]

sorted_swap = sorted(swap_avg_by_hour, reverse=True) # we sorted the new list

print(‘Top 5 Hours for Ask Posts Comments’)

for average, hour in sorted_swap[:5]:

hour_object = dt.datetime.strptime(hour, ‘%H’) # convert the string to datetime object

time = hour_object.strftime(’%H:%M’) # format the datetime object

print(’{time}: {average:.2f} comments per post’.format(time=time, average=average) )

It should become clearer to you. if you see a star, * in the above codes above, just take it out/delete it. Good Luck with your studies!!! You will find me @AlMokgalaka twitter and Linkedin.