【发布时间】:2020-01-31 21:47:42
【问题描述】:
我有一个由时间戳组成的数据集,如下所示:
['2019-12-18T12:06:55.697975Z"', '2019-12-18T12:06:55.707017Z"',...]
我需要一个for 循环,它将遍历所有时间戳并将每个时间戳转换为时间结构。但是我创建的内容不起作用 - 我不确定数据类型以及使用字符串时的索引。
我的尝试如下:
from time import struct_time
for idx in enumerate(tm_str): #tm_str is a string:['2019-12-18T12:06:55.697975Z"', ...]
a=idx*30+2 #a should be first digit in year - third position in string -
b=idx*30+6 # b should last dgit of year, 30 is period to next year
tm_year=tm_str[a:b]
月、日、小时等应该以类似的方式完成。
【问题讨论】:
-
这能回答你的问题吗? Converting string into datetime