LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

5/8 Guided Project: Exploring Hacker News Posts

Screen Link:
!
image|621x500

My Code:

import datetime as dt
result_list = []

for row in ask_posts:
    created_at = row[6]
    result_list += created_at
    average_ask_comments = int(len(result_list))/len_ask_posts
    
print(average_ask_comments)

counts_by_hour = {}
comments_by_hour = {}

for row in result_list:
    date_and_time = row[0]
    date_and_time = dt.datetime.strptime(date_and_time, %m/%d/%Y %H:%M)
    post_time = date_and_time.strftime(%H)
    if post_time not in counts_by_hour:
        counts_by_hour[post_time] = 1
        comments_by_hour[post_time] = int(row[1])
    else:
        counts_by_hour[post_time] +=1
        comments_by_hour[post_time] += int(row[1])

print(counts_by_hour)
print("")
print(comments_by_hour)    

What I expected to happen:
Format should be working

What actually happened:

 File "<ipython-input-30-f227e5b920b9>", line 16
    date_and_time = dt.datetime.strptime(date_and_time, %m/%d/%Y %H:%M)
                                                        ^
SyntaxError: invalid syntax

Hi @paulvi92,

Welcome to the Community!

You forgot the quote marks for the format that you use in strptime. And, by the way, later in the code you have to add quote marks also to the format used in strftime.

1 Like

Thank you for the short notice and for the reply.

1 Like

AI for Earth Monitoring - Online course

:question:What course is about​:question:
:white_check_mark: How to apply data science to datasets of Earth images collected by satellites

:man_technologist:Who is the course for?:woman_technologist:
This course would benefit people interested in jumping into the world of data science and gaining experience working with real Earth observation image data.

:muscle:What you will learn?:muscle:
:one:How to apply Python and libraries to real problems with Earth observation data
:two:How to work with machine learning using image datasets.
:three:How to process large datasets and many more

:information_source:Info​:information_source:
:alarm_clock:Start date: 18 Oct. 2021
:timer_clock:Duration: 6 weeks
:writing_hand:Registered: >3500 data enthusiats registered already
:money_with_wings:Cost: Free

:eyes:Interested? Check more details here: registration (Artificial Intelligence (AI) for Earth Monitoring - FutureLearn)