对CSV文件

时间:2017-06-29 01:59:49

标签: python

我想将此API响应传递给一个简单的CSV文件:

[[1467167400,576.01,576.01,576.01,576.01,0.72],
[1467166200,579.03,579.03,579.03,579.03,0.02],
[1467165900,580,580,580,580,1.6505],
[1467165600,580,580.53,580.53,580.01,0.5467],
[1467165000,584,584.63,584.63,584,10.438751879999998],
[1467164700,585,586.48,586.48,585,1.0923],
[1467164100,585,587.72,587.3,587.72,2.61],
[1467163800,587.66,587.66,587.66,587.66,0.04],
[1467163200,588.02,588.02,588.02,588.02,0.2],
[1467162600,587.84,587.84,587.84,587.84,0.16],
[1467162000,588.1,588.26,588.26,588.1,0.12000000000000001]]

我想要一个像这样的CSV文件:

2017-05-28 14:00:00 UTC,1922.51735897436,1961.0,1879.01
2017-05-28 15:00:00 UTC,1869.88877403846,1906.28,1827.14
2017-05-28 16:00:00 UTC,1860.06581132075,1897.83,1833.81
2017-05-28 17:00:00 UTC,1885.3259798995,1906.99,1859.01
2017-05-28 18:00:00 UTC,1881.34923469388,1907.32,1859.01
2017-05-28 19:00:00 UTC,1887.00946153846,1905.82,1867.04
2017-05-28 20:00:00 UTC,1854.78940860215,1877.0,1840.01
2017-05-28 21:00:00 UTC,1870.5975,1886.99,1845.36
2017-05-28 22:00:00 UTC,1899.98381756757,1921.44,1875.97
2017-05-28 23:00:00 UTC,1923.40009009009,1940.03,1906.86

我怎样才能轻松做到这一点?如果我想改变行的顺序,比如价格变低到高价,反之亦然?

1 个答案:

答案 0 :(得分:1)

你可以遍历你拥有的列表并写入文件/打印,如此

for item in dict:
  comma = ''
  out = ""
  for element in item:
    out.join(comma,element)
    comma = ','
  print(out)