(python/json/mysql)关于json中不会传输到db的财务数据的建议

p4tfgftt  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(318)

我有一个json文件,包含原始财务数据,包括ohlc、数量、交易等。除ohlc外的所有数据都将正确传输到我设置的mysql数据库。ohlc数据在传输到数据库后仅为零。原始json数据如下所示:
[[1512086400000, "0.00001204", "0.00001209", "0.00001161", "0.00001183", "771721.00000000", 1512086699999, "9.10638040", 126, "359700.00000000", "4.22792312", "52516956.22676400"], [1512086700000, "0.00001189", "0.00001194", "0.00001183", "0.00001189", "119120.00000000", 1512086999999, "1.41575664", 44, "49016.00000000", "0.58377518", "52659721.84287900"], [1512087000000, "0.00001191", "0.00001196", "0.00001183", [1512087600000, "0.00001187", "0.00001190", "0.00001171", "0.00001174", "312477.00000000", 1512087899999, "3.69618651", 63, "155121.00000000", "1.84118817", "53289721.44287900"], … …
其中第一个值是时间,引号中的下四个值是ohlc数据,引号中的下一个值是体积。我最初怀疑由于某种原因,引用阻止了传输,但奇怪的是,卷也在引用中,传输到我的数据库没有问题。
我考虑迭代文件并将其复制到另一个json文件中,去掉引号。不过,我不确定这一努力是否会成功,所以我想看看那些可能更了解情况的人的建议是什么。

holgip5t

holgip5t1#

这似乎是一个列表列表,因此您可以使用numpy将字符串值转换为十进制值,如下所示:

a=[[1512086400000, "0.00001204", "0.00001209", "0.00001161", "0.00001183", "771721.00000000", 1512086699999, "9.10638040", 126, "359700.00000000", "4.22792312", "52516956.22676400"],
   [1512086700000, "0.00001189", "0.00001194", "0.00001183", "0.00001189", "119120.00000000", 1512086999999, "1.41575664", 44, "49016.00000000", "0.58377518", "52659721.84287900"]]

将此列表转换为numpy数组:

import numpy as np
a=np.array(a)
a.astype(np.float)
print(a)

输出:

[[1.51208640e+12 1.20400000e-05 1.20900000e-05 1.16100000e-05
  1.18300000e-05 7.71721000e+05 1.51208670e+12 9.10638040e+00
  1.26000000e+02 3.59700000e+05 4.22792312e+00 5.25169562e+07]
 [1.51208670e+12 1.18900000e-05 1.19400000e-05 1.18300000e-05
  1.18900000e-05 1.19120000e+05 1.51208700e+12 1.41575664e+00
  4.40000000e+01 4.90160000e+04 5.83775180e-01 5.26597218e+07]]

相关问题