Python Forum

Full Version: Time Data does not match format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have the following code:

import pandas as pdm
from datetime import datetime,timedelta
timeFormat = '%d/%m?%y %H:%M:%S'


dataFrame = pdm.read_csv('C:\\', sep=',', index_col=None)
list_stamps = dataFrame['Timestamp'].tolist()
list_stamps_date = [datetime.strptime(i,timeFormat) for i in list_stamps]
and unfortunately, when i'm trying to read the following string "22/10/18 08:00:00" i get the following error:

Error:
ValueError: time data '22/10/18 08:00:00' does not match format '%d/%m?%y %H:%M:%S'
for clarity the full error is:
Error:
Traceback (most recent call last): File "C:/Users/ashle/PycharmProjects/CSV_Handling/TradeDataManipulation/Momentum.py", line 9, in <module> list_stamps_date = [datetime.strptime(i,timeFormat) for i in list_stamps] File "C:/Users/ashle/PycharmProjects/CSV_Handling/TradeDataManipulation/Momentum.py", line 9, in <listcomp> list_stamps_date = [datetime.strptime(i,timeFormat) for i in list_stamps] File "C:\Program Files\Python36\lib\_strptime.py", line 565, in _strptime_datetime tt, fraction = _strptime(data_string, format) File "C:\Program Files\Python36\lib\_strptime.py", line 362, in _strptime (data_string, format)) ValueError: time data '22/10/18 08:00:00' does not match format '%d/%m?%y %H:%M:%S' Process finished with exit code 1
I'm early stages of teaching myself python so I'm sure someone will groan at my stupidity, but I can't seem to spot the obvious problem!!!.

all help much appreciated
you have ? instead of / in the format string
%d/%m?%y %H:%M:%S
Haha - I'm so sorry you actually had to look at that. Thanks so much.....
really appreciate it