Using strptime to parse String as Dates

My Code:

date_format = "%m/%d/%y %H:%M"
for row in potus:
    start_date = row[2]
    start_date = dt.datetime.strptime(start_date, date_format)
    row[2] = start_date

What actually happened:

ValueError                                Traceback (most recent call last)
<ipython-input-9-f3e8b98ddafb> in <module>
      3 for row in potus:
      4     start_date = row[2]
----> 5     start_date = dt.datetime.strptime(start_date, date_format)
      6     row[2] = start_date

~\anaconda3\lib\ in _strptime_datetime(cls, data_string, format)
    566     """Return a class cls instance based on the input string and the
    567     format string."""
--> 568     tt, fraction, gmtoff_fraction = _strptime(data_string, format)
    569     tzname, gmtoff = tt[-2:]
    570     args = tt[:6] + (fraction,)

~\anaconda3\lib\ in _strptime(data_string, format)
    347     found = format_regex.match(data_string)
    348     if not found:
--> 349         raise ValueError("time data %r does not match format %r" %
    350                          (data_string, format))
    351     if len(data_string) != found.end():

ValueError: time data 'appt_start_date' does not match format '%m/%d/%y %H:%M'

Hi guys, I’m new to python. I’m trying to practice the “Using strptime to parse String as Dates” task on my Jupiter Notebook with the data provided, though I’ve got an error message. Can anybody help me with this error? Thanks a lot.

I didn’t find any issue. Kindly refresh and rerun the code.


1 Like

Hey, florah3979.

You probably called the start_date variable as appt_start_date before. Just like pablajaspreet94, try to refresh and rerun the code. It’s working normal.

Thanks for your response. There is no error when I run these code on Dataquest. Though I’ve tried to practice those code on my Jupiter Notebook, I’ve got an error message.

Thanks for your responses guys! I’ve already found the mistake which is caused by me forgetting to exclude the head of data. Have a good day guys.