且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Pandas数据框中将日期转换为ISO-8601 DateTime格式

更新时间:2023-02-03 23:33:58

使用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