[Tutor] How to convert string to date time format?
C W
tmrsg11 at gmail.com
Fri Jul 19 22:44:36 EDT 2019
Hello all,
I have a date time string that looks like the following.
0 2015-07-01 00:01:44.538420-08:00
1 2015-07-01 00:27:58.717530-08:00
2 2017-07-01 07:07:48.391376-08:00
I have tried the following two different methods, both did not work.
Method one: pandas
import pandas as pd
stamp = pd.to_datetime(my_string, format='%Y%m%d %H:%M:%S')
Method two: datetime package
from datetime import datetime
datetime.strptime(my_string, '%Y-%m-%d %H:%M:%S')
Are both ways suppose to work? Also, does it matter if there are decimals
after seconds? Thanks a lot!
More information about the Tutor
mailing list