8

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

0

1 Answer 1

15

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.