Python将numpy数组写入CSV文件[重复]

时间:2021-06-01 21:41:41

This question already has an answer here:

这个问题在这里已有答案:

I'm trying to write a 2D numpy array to a CSV File I tried this:

我正在尝试将2D numpy数组写入CSV文件我试过这个:

import csv
import numpy as np

w = csv.writer(open('main.csv','w'))

Nlayers=23
N=364
TempLake=np.zeros((N,Nlayers))

for i in xrange(N-1):
    TempLake[i+1]=TempLake[i]+100

w.writerow(TempLake)

outfile = open('main.csv', 'w')

writer = csv.writer(outfile)

ar=np.array(TempLake)

for row in TempLake:
    writer.writerow(row)
outfile.close()

Why some of the rows still have quotes? Thank you

为什么有些行仍然有引号?谢谢

1 个解决方案

#1


13  

Use numpy.savetxt, specifying a comma as the delimiter.

使用numpy.savetxt,将逗号指定为分隔符。

#1


13  

Use numpy.savetxt, specifying a comma as the delimiter.

使用numpy.savetxt,将逗号指定为分隔符。