Is there an error in the given answer, the strftime part?

I rarely can connected to the virtual machine in the classroom, so I practice locally, got confused for above code in the screenshot I took:

Should row[2] be first transfer to a datatime object, then use strptime() function to create a string from it?
The given answer use the strings from row[2] directly, please check this part: 6. Using Strftime to format dates On working with dates and times in Python, thank you.

Hi @evamalloc

Welcome to our Dataquest Community.

Actually, element of row[2] already in datetime format, variable month_dt passes in method strftime and return after calculation in string format.

You can check the format of 3nd element of row (it is of list type), by running this command.

print(type(potus[0][2]))     # Output:- <class 'datetime.datetime'>

Hope this helps :slight_smile: .

Thank you for answering my question, I understand what you mean, but I have a new puzzle which is when row[2] be updated to datetime format?

The online programming platform doesn’t give any comments that says row[2] already been converted to be datetime and the raw type for row[2] from the dataset is string format.

@evamalloc see slide 5, where you are converting all 3nd element of each potus list into datetime format.