Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Writing a numpy array to a CSV File [duplicate]

Tags:

python

csv

numpy

I'm 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 some of the rows still have quotes? Thank you

like image 594
user1419224 Avatar asked Jun 02 '12 12:06

user1419224


1 Answers

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

like image 169
Steven Rumbalski Avatar answered Oct 22 '22 18:10

Steven Rumbalski