我正在尝试将数组的值写入 python 中的 .csv 文件。但是当我在 excel 中打开文件时,数据显示在一行中。我想要一列,其中数组的每个成员都是一行。
数组“testLabels”的形式是:
array(['deer', 'airplane', 'dog', ..., 'frog', 'cat', 'truck'],
dtype='<S10')
我用来写入 csv 的代码是:
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])
关于python - 将数组写入 csv python(一列),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21465447/