Hacker Posts: calculating avg number of comments

Screen Link:
https://app.dataquest.io/m/356/guided-project%3A-exploring-hacker-news-posts/6/calculating-the-average-number-of-comments-for-ask-hn-posts-by-hour

My Code: See attached Notebook for code

I wrote a combined code for steps 5 and 6. I stored the final answer in a dictionary and not a list like it is in the instructions. However, I replaced dict with list and got the same answer. Just keeping the dict as is in my code.

The result for number of comments per hour went wrong for me.
This in turn caused my average numbers to go wrong.

Can you please help me understand where my code went wrong?

Thank you very muchBasics (1).ipynb|attachment (7.4 KB)
What I expected to happen:
[[‘09’, 5.5777777777777775],
[‘13’, 14.741176470588234],
[‘10’, 13.440677966101696],
[‘14’, 13.233644859813085],
[‘16’, 16.796296296296298],
[‘23’, 7.985294117647059],
[‘12’, 9.41095890410959],
[‘17’, 11.46],
[‘15’, 38.5948275862069],
[‘21’, 16.009174311926607],
[‘20’, 21.525],
[‘02’, 23.810344827586206],
[‘18’, 13.20183486238532],
[‘03’, 7.796296296296297],
[‘05’, 10.08695652173913],
[‘19’, 10.8],
[‘01’, 11.383333333333333],
[‘22’, 6.746478873239437],
[‘08’, 10.25],
[‘04’, 7.170212765957447],
[‘00’, 8.127272727272727],
[‘06’, 9.022727272727273],
[‘07’, 7.852941176470588],
[‘11’, 11.051724137931034]]

What actually happened:
{‘12’: 8.859375, ‘04’: 13.87741935483871, ‘09’: 12.96103896103896, ‘07’: 10.104166666666666, ‘05’: 11.027397260273972, ‘01’: 13.351724137931035, ‘08’: 17.296875, ‘06’: 12.0, ‘11’: 9.396825396825397, ‘02’: 16.951515151515153, ‘10’: 9.784615384615385, ‘03’: 28.811764705882354}Basics (1).ipynb (7.4 KB)

@souhasini.madhu

Your code is not uploaded in your post.

I have uploaded it again.

Thanks.

@souhasini.madhu,

The error in your code is here: hour = date.strftime("%I").
The correct line of code should be hour = date.strftime("%H")

Kindly note that %I represents Hour in 12-hour clock while %H represents the Hour in 24-hour clock.

Let me know if it solves the problem.

Thank you so much! I was under the assumption that strftime only controls the display aspect of time.

Thanks again!

@souhasini.madhu,

You are welcome.
Kindly check your DQ inbox.