运行中的异常的结果脚本:类型错误INT()参数必须是一个字符串,一个字节状物体或数字,而不是“datetime.datetime”在行 data = np.asarray(tmp, dtype=data_type)
from datetime import datetime
import numpy as np
data_type = [("Scan", "i4"), ("Time", "M8[us]"), ("101 (C)", "f8"), ("Alarm
101", "?"), ("102 (C)", "f8"), ("Alarm 102", "?")]
data_text = """1,12/6/2018 09:22:25:462,22.661,0,22.046,0
2,12/6/2018 09:22:35:446,22.874,0,22.289,0
3,12/6/2018 09:22:45:446,22.948,0,22.385,0"""
def main():
tmp = []
for line in data_text.split("\n"):
dataLine = []
for (h, _), v in zip(data_type, line.split(",")):
if h == "Scan":
dataLine.append(int(v))
elif h == "Time":
# dataLine.append(datetime.strptime(v, "%m/%d/%Y %H:%M:%S:%f"))
dataLine.append(np.datetime64(datetime.strptime(v, "%m/%d/%Y %H:%M:%S:%f"), "us"))
elif "Alarm" in h:
dataLine.append(bool(v))
else:
dataLine.append(float(v))
tmp.append(dataLine)
data = np.asarray(tmp, dtype=data_type)
if __name__ == "__main__":
main()
从 numpy 文档中,我看不出它不应该工作的理由。我能想到的最好的一点是,我对 numpy 结构化数组遗漏了一些东西。这是一个语法问题,一个 numpy 错误,甚至可能与 numpy 有关?
慕婉清6462132
相关分类