我有一个包含 ohlc 数据的列表:
[(1360710000.0, 69.06, 69.67, 68.53, 69.53, 550000.0, 69.53),
(1360623600.0, 68.98, 69.05, 68.39, 68.94, 604200.0, 68.94)]
并希望它转换成一个结构如下的 numpy 数组:
array([ (1352934000, 63.130001068115234, 63.59000015258789, 62.900001525878906, 63.16999816894531, 816300.0, 63.16999816894531),
(1353020400, 62.970001220703125, 63.529998779296875, 62.599998474121094, 62.61000061035156, 942000.0, 62.61000061035156),
(1353279600, 63.0, 64.97000122070312, 63.0, 64.87999725341797, 812800.0, 64.87999725341797),
(1353366000, 64.44999694824219, 65.27999877929688, 64.29000091552734, 65.23999786376953, 467700.0, 65.23999786376953),
(1353452400, 65.16999816894531, 65.4000015258789, 64.58999633789062, 64.8499984741211, 417700.0, 64.8499984741211)],
dtype=[('time', '<i4'), ('open', '<f4'), ('high', '<f4'), ('low', '<f4'), ('close', '<f4'), ('volume', '<f4'), ('amount', '<f4')])
任何尝试都会导致预期的错误结构:
np.array(list, dtype=Day)
array([[1360710000.0, 69.06, 69.67, 68.53, 69.53, 550000.0, 69.53],
[1360623600.0, 68.98, 69.05, 68.39, 68.94, 604200.0, 68.94]], dtype=object)