Python Writing a numpy array to a CSV file

I am trying to write a 2D numpy array to a CSV file. I tried this:

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 do some lines have quotation marks? Thanks you

+6
source share
1 answer

Use numpy.savetxt , specifying a comma as a separator.

+13
source

Source: https://habr.com/ru/post/917243/


All Articles