本文介绍了如何在Pandas数据框中将日期转换为ISO-8601 DateTime格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的数据框(使用python/pandas),希望转换
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
如何将"q_date"字段转换为SO-8601 DateTime格式(yyyy-MM- ddTHH:mm:ssZ)?
How can I convert the 'q_date' field into SO-8601 DateTime format (yyyy-MM- ddTHH:mm:ssZ)?
谢谢.
推荐答案
使用pandas datetools解析器解析日期,然后使用标准的python strftime
函数将其格式化.
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
这篇关于如何在Pandas数据框中将日期转换为ISO-8601 DateTime格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!