Z
, or Military Time
is not supported in Datetime
. The solution is to either remove the Z
or replace it with +00:00
. Your code becomes:
df['dateAdded'] = pd.to_datetime(df['dateAdded'].rsplit('Z', 1)[0], format= '%Y-%d-%mT%H:%M:%S')
Or if you are using a newer version that supports the Military Time then your solution is to simply replace the %Z
in your format
with %z
(small letter).
df['dateAdded'] = pd.to_datetime(df['dateAdded'].rsplit('Z', 1)[0], format= '%Y-%d-%mT%H:%M:%S%z')
Another (better IMO) approach is to convert the datetime without using pandas
.
from datetime import datetime
df['dateAdded'] = datetime.fromisoformat(df['dateAdded'])
though you're going to have to edit the code above to go over the entire column.