Python将numpy数组写入CSV文件 [英] Python Writing a numpy array to a CSV File

查看:2440
本文介绍了Python将numpy数组写入CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个2D numpy数组到CSV文件
我试过这个:

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

推荐答案

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

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

这篇关于Python将numpy数组写入CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆