PythonAPI:Data conversion error: unsupported type [<class 'datetime.datetime'>]

使用用 mtw 接口,把数据写入一个表 timestring=datetime.strptime(str(futures_[i].nActionDay)+""+str(futures_[i].nTime).zfill(9),'%Y%m%d%H%M%S%f')
writer.insert(futures_[i].szWindCode.decode('utf-8'), timestring,futures_[i].nMatch), 但是系统反馈 Data conversion error: unsupported type [<class 'datetime.datetime'>], 之前是在 程序中明确做了转换, s.run("data = select Symbol, timestamp(Datetime) as Datetime, Price from tmpData")。 但是 MTW 接口下怎么做这种日期的转换呀?

请先 登录 后评论

1 个回答

veryOrdinary

PythonAPI 不支持 datetime.datetime 类型的日期,需要转成 np.datetime64 类型,可以用 pd.to_datetime 进行转换。例如:

下述数据时间戳的格式为:2021.09.01T10:01:00.123

data_path = "/path/20210901tick.csv"
df = pd.read_csv(data_path)
df["SecurityID"] = df["SecurityID"].astype('str')+".SH"
df["TradeTime"] = pd.to_datetime(df["TradeTime"], format='%Y.%m.%dT%H:%M:%S.%f')


请先 登录 后评论