Time data doesn't match format specified error

Viewed 1758

I'm a python beginner and am trying to run a time-series analysis with some practice data. I know I have to convert the str date format into datetime. I have already imported pandas and datetime. My dates are originally in the following format:

df.loc[0,'date']
'2017-01-27'

I have tried the line below in order to get the data into a readable format

df['date'] = pd.to_datetime(df['date'], format = '%Y-%m-%d')

Yet I keep getting the error code:

ValueError: time data date doesn't match format specified

Is my format code written correctly or am I missing some syntax anywhere? Any and all help is much appreciated - Thanks!

1 Answers

try this:

df['date']= pd.to_datetime(df['date'], errors='ignore')
Related