Answer a question

I have the dataframe below (using python/pandas) and wish to convert the

q_string          q_visits  q_date
red               1790  02/10/2012 00:00
blue              364   02/10/2012 00:00
current           280   02/10/2012 00:00
molecular         259   02/10/2012 00:00
cell              201   02/10/2012 00:00

How can I convert the 'q_date' field into SO-8601 DateTime format (yyyy-MM- ddTHH:mm:ssZ)?

Thanks in advance.

Answers

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
Logo

学AI,认准AI Studio!GPU算力,限时免费领,邀请好友解锁更多惊喜福利 >>>

更多推荐