Screen Link: https://app.dataquest.io/m/353/working-with-dates-and-times-in-python/5/using-strptime-to-parse-strings-as-dates
Your Code:
import datetime as dt
# print(potus[:2])
date_format = "%m/%d/%y %H:%M"
for each_list in potus:
appt_start_date = each_list[2]
appt_start_date = dt.datetime.strptime(appt_start_date, date_format)
# print(appt_start_date)
each_list[2] = appt_start_date
print(potus[:3])
What I expected to happen:
I expected the below output:
[[‘Joshua T. Blanton’, ‘2014-12-18T00:00:00’, 2015-01-06 09:30:00, ‘1/6/15 23:59’, ‘’, ‘potus’, ‘west wing’, ‘JointService Military Honor Guard’], [‘Jack T. Gutting’, ‘2014-12-18T00:00:00’, 2015-01-06 09:30:00, ‘1/6/15 23:59’, ‘’, ‘potus’, ‘west wing’, ‘JointService Military Honor Guard’], [‘Bradley T. Guiles’, ‘2014-12-18T00:00:00’, 2015-01-06 09:30:00 ,‘1/6/15 23:59’, ‘’, ‘potus’, ‘west wing’, ‘JointService Military Honor Guard’]]
What actually happened: I am getting the below result:
[[‘Joshua T. Blanton’, ‘2014-12-18T00:00:00’, datetime.datetime(2015, 1, 6, 9, 30), ‘1/6/15 23:59’, ‘’, ‘potus’, ‘west wing’, ‘JointService Military Honor Guard’], [‘Jack T. Gutting’, ‘2014-12-18T00:00:00’, datetime.datetime(2015, 1, 6, 9, 30), ‘1/6/15 23:59’, ‘’, ‘potus’, ‘west wing’, ‘JointService Military Honor Guard’], [‘Bradley T. Guiles’, ‘2014-12-18T00:00:00’, datetime.datetime(2015, 1, 6, 9, 30), ‘1/6/15 23:59’, ‘’, ‘potus’, ‘west wing’, ‘JointService Military Honor Guard’]]
Other details:
I expected appt_start_date
to be formatted. If I print separately, I am able to see the expected result, but not when I am assigning it back to the list.
Thanks,
Venkat