【发布时间】:2019-05-11 15:37:50
【问题描述】:
我有以下<class 'numpy.ndarray'> 类型的数组
array([20181010, 20181031, 20181116, 20181012, 20181005, 20181008,
20181130, 20181011, 20181005, 20181116])
如何将其成分从当前类型<class 'numpy.int64'> 转换为numpy 中的日期时间?我想找到一种快速的方法,我的理解是使用循环或列表理解,以及将此 numpy.array 转换为 pandas 或 list 会更慢。
如果我错了,请纠正我。
附:这个问题可能已经在某处得到解答,但我找不到一个可行的解决方案。
【问题讨论】:
-
@Nixon,但那里的答案并不理想。肯定有更好的目标吗?
-
我认为
@Sebastian's answer is superior to the duplicate, https://stackoverflow.com/questions/27103044/converting-datetime-string-to-datetime-in-numpy-python, even though both usepd.to_datetime`。 -
@hpaulj 我尝试了重复,我尝试了塞巴斯蒂安的回答,事实上我也同意你的观点。因此,我投票并标记为正确的原因(以及为什么我在提问时无法从标记为重复的内容中得到完整的答案)。
标签: python python-3.x numpy datetime