rhanly
rhanly

Reputation: 91

Converting pandas Column to datetime

I am trying to convert a pandas column to datetime. This is my error message.

ValueError: time data '01-JUN-17 00:00:00' does not match format '%d-%b-%y %H.%M.%S' (match)

This is my code :

df['dayofservice'] =  pd.to_datetime(df['dayofservice'], format = '%d-%b-%y %H.%M.%S')

I have read this documentation to ensure my format is correct : https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior

It's still not working for me.

Upvotes: 3

Views: 10244

Answers (2)

EdChum
EdChum

Reputation: 394439

pandas is man/woman enough to parse this without a format field:

In[90]:
pd.to_datetime('01-JUN-17 00:00:00')

Out[90]: Timestamp('2017-06-01 00:00:00')

So this should work:

df['dayofservice'] =  pd.to_datetime(df['dayofservice'])

Upvotes: 4

jezrael
jezrael

Reputation: 863681

Change . to : in times like:

df['dayofservice'] =  pd.to_datetime(df['dayofservice'], format = '%d-%b-%y %H:%M:%S')

Upvotes: 0

Related Questions