将数组写入csv python(一列) [英] Writing array to csv python (one column)
本文介绍了将数组写入csv python(一列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将数组的值写入python中的.csv文件.但是,当我在excel中打开文件时,数据显示在一行中.我想有一列,其中数组的每个成员都是一行.
I'm trying to write the values of an array to a .csv file in python. But when I open the file in excel, the data is shown in one row. I want to have one column where each member of the array is a row.
"testLabels"数组的形式为:
The array "testLabels" is of the form:
array(['deer', 'airplane', 'dog', ..., 'frog', 'cat', 'truck'],
dtype='<S10')
我用来写入csv的代码是:
And the code I use to write to the csv is:
import csv
resultFile = open("/filepath",'wb')
wr = csv.writer(resultFile)
wr.writerows([testLabels])
任何帮助将不胜感激.
推荐答案
尝试一下:
wtr = csv.writer(open ('out.csv', 'w'), delimiter=',', lineterminator='\n')
for x in arr : wtr.writerow ([x])
这篇关于将数组写入csv python(一列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文