我没有尝试np.savetxt
在下面的上下文中使用它,也许只要文件以附加模式打开,它就可以使用,但这是我试图做的解决方案。但是,它可能不是最有效的..
def _as_csv(self, values):
vals = ','.join([str(i) for i in values])
return vals + '\n'
def output(self, filename, series_cnt, series_name, series_type, startdate, N, values, step = 1000):
""" outputs data to a file """
starttime = startdate
num_imports = (N / step) + 1
outfile = open(filename.format(series_cnt, i), 'w')
outfile.write('#{0},{1},{2},\n'.format('TEST', startdate.strftime('%Y%m%d%H%M%S000'), str(num_imports)))
for i in range(0, N, step):
line_start = '/Test/{0},{1},{2},{3},'.format(series_name, series_type, starttime.strftime('%Y%m%d%H%M%S000'), step)
outfile.write(line_start)
nxt = i + step
starttime = starttime + dt.timedelta(hours=step)
outfile.write(self._as_csv(values[i:nxt]))
outfile.close()