I know this question is out there quite a bit, but I cannot find a solution for my case. I have a DataFrame with a column Time in string format that I need to convert to datetime. Ultimately, I want the date as an int for ML purposes, but I cannot seem to get it to datetime first.
I have:
testDate = tripOrig[' Time'][0]
newDate = dt.datetime.strptime(testDate,'%d-%b-%Y %H:%M:%S.%f %Z')
Where the dates are strings like:
05-Jun-2016 00:00:00.000 EDT
For whatever reason, I keep getting the error that it is in the wrong format. I cannot for the life of me figure out what I am doing wrong. I checked the datetime docs over many times but I keep getting:
ValueError: time data '05-Jun-2016 00:00:00.000 EDT' does not match format '%d-%b-%Y %H:%M:%S.%f %Z'
What am I missing here?!?
As another note, I have also tried:
tripOrig['correct date'] = pd.to_datetime(tripOrig[' Time'])
This is very slow, throws a timezone warning, and does not account for seconds when convert to int, so I cannot use it.
How can I get this converted?