Python中的ISO 8601的日期时间
作者:互联网
我有这个数据帧:
timestamp dttm_utc value estimated anomaly
0 1325376300 2012-01-01 00:05:00 16.9444 0 NaN
1 1325376600 2012-01-01 00:10:00 16.6837 0 NaN
2 1325376900 2012-01-01 00:15:00 16.6837 0 NaN
3 1325377200 2012-01-01 00:20:00 16.9444 0 NaN
4 1325377500 2012-01-01 00:25:00 16.1623 0 NaN
5 1325377800 2012-01-01 00:30:00 16.6837 0 NaN
6 1325378100 2012-01-01 00:35:00 16.1623 0 NaN
7 1325378400 2012-01-01 00:40:00 16.4230 0 NaN
8 1325378700 2012-01-01 00:45:00 16.1623 0 NaN
9 1325379000 2012-01-01 00:50:00 17.2051 0 NaN
如何将dttm_utc更改为带有时区偏移的ISO8601格式?
解决方法:
如果您的对象是日期时间对象,则可以使用obj.isoformat()直接将其转换为ISO.如果您的对象不是datetime对象,则可以使用strptime进行转换.
比如说,如果你使用熊猫:
my_obj['dttm_iso8601'] = datetime.datetime.strptime(
my_obj['dttm_utc'],
'%Y-%m-%s %h:%m:%s'
).isoformat()
标签:iso8601,python,datetime 来源: https://codeday.me/bug/20190910/1799827.html