How do I convert dates into ISO-8601 DateTime format in a Pandas dataframe
I would use pd.to_datetime
and the .dt accessor
pd.to_datetime(df['q_date']).dt.strftime('%Y-%m-%dT%H:%M:%SZ')
See also strftime() and strptime() Format Codes
Use the pandas datetools parser to parse the date and then format it using the standard python strftime
function.
>>> df['q_date'].apply(
lambda x: pd.datetools.parse(x).strftime('%Y-%m-%dT%H:%M:%SZ'))
0 20120210T00:0000Z
1 20120210T00:0000Z
2 20120210T00:0000Z
3 20120210T00:0000Z
4 20120210T00:0000Z
Name: q_date, dtype: object
use to_datetime for pandas datetime format and use strftime to convert to required format.
currentDate = pd.to_datetime(df['q_date'])
convertDate = currentDate.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
or use isoformat to convert to ISO format.
convertDate = currentDate.isoformat()