【发布时间】:2018-10-19 13:27:42
【问题描述】:
您好,我有一个 UTC 格式的数字数组。格式是 HH.MM.SS.MS,即小时分钟秒和毫秒。我想将整个数字转换为毫秒。所以我正在提取如下所示的前 2 位数字
hh=int(str(x[1])[:2]) # returns 42 where hours and minutes mixed
# My data also start with non zero for example x=142826.00
# doing the same operation like above returns 14( It is perfect). So intention is when 04 extract only 4 and if it is 14 extract 14.
042826.00
042826.25
042826.50
042826.75
042827.00
042827.25
042827.50
042827.75
042828.00
042828.25
042828.50
042828.75
042829.00
042829.25
042829.50
042829.75
042830.00
042830.25
042830.50
042830.75
如何提取并转换为毫秒。
【问题讨论】:
-
如果它们不是数字,为什么要将它们作为数字?
-
你得到的是数字而不是文本?
-
@Ignacio Vazquez-Abrams。是的
-
首先你需要了解你的数据类型,如果你
print(type(x))会得到什么?你确定数据在int而不是'str'吗?好像是int,不会有任何前缀0,042826.00只会显示为42826.0。 -
@hcheung。明白了。它是浮点数,但小时数从 1 位数变为 2 位数格式。即有时 5 小时和 11 小时,具体取决于数据的持续时间。
标签: python-2.7 pandas numpy