1

I am trying to convert to datetime in pandas dataframe, where name of timezone is included. I have tried the following but it yields an error:

d = {'col1': ['Sun Dec 31 00:00:00 EAT 1899', 'Mon Mar 02 00:00:00 EAT 2020']}
x = pd.DataFrame(data=d)
pd.to_datetime(x['col1'], format='%a %b %d %H:%M:%S %Z %Y', errors='coerce')

0   NaT
1   NaT
Name: col1, dtype: datetime64[ns]

Is there any way to convert to datetime this way? If not, how to ignore the timezone name?

0

1 Answer 1

1

you can use dateutil:

import dateutil
print (x['col1'].apply(dateutil.parser.parse))
0   1899-12-31
1   2020-03-02
Name: col1, dtype: datetime64[ns]

or to ignore the part with the timezoen, something like:

pd.to_datetime(x['col1'].str[:20] + x['col1'].str[24:])

but not sure if it is interesting

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.