3

So I try to convert an object to pandas datetime with the to_datetime option. However it is not working.

My code:

ship_date = pd.to_datetime(d['shipmentDate'])

print(ship_date.head())

Output:

0    2019-11-08 18:57:31+01:00
1    2019-11-08 16:30:02+01:00
2    2019-11-08 15:28:32+01:00
3    2019-11-08 11:56:32+01:00
4    2019-11-08 11:56:02+01:00
Name: shipmentDate, dtype: object

Even when trying to use format like so: ship_date = pd.to_datetime(d['shipmentDate'], format='%Y-%m-%d %H:%M:%S%z')

I still get an object and not a datetime. What am I doing wrong?

1
  • Your code is working fine for me with and without specifying the format option. Can you provide more details such as the original type of 'shipmentDate' column in the DataFrame? Commented Nov 9, 2019 at 13:02

1 Answer 1

4

Your datetime has different time zones. You can pass utc=True to to_datetime.

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.