1

I get an error when I try to convert a datetime string to a datetime object:

df['R_DATE'] = pd.to_datetime(df['R_DATE'], format='%a %b %d %H:%M:%S %Z %Y')

Error is:

...
File "pandas\_libs\tslibs\strptime.pyx", line 141, in pandas._libs.tslibs.strptime.array_strptime
  ValueError: time data 'Mon Oct 18 00:00:00 EDT 2021' 
    does not match format '%a %b %d %H:%M:%S %Z %Y' (match)

From what I can tell format appears to match the datetime string value. I'm not sure if the timezone value (EDT) is causing issues.

1 Answer 1

1

nvm. found the answer I was looking for.

import dateutil

tzdict = {'EST': dateutil.tz.gettz('America/New_York'),
      'EDT': dateutil.tz.gettz('America/New_York')}

df['R_DATE'] = df['R_DATE'].apply(dateutil.parser.parse, tzinfos=tzdict)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.