python - 将数组写入 csv python(一列)

标签 python arrays excel csv machine-learning

我正在尝试将数组的值写入 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/

相关文章:

python - Matplotlib 和 Numpy 与某些 Pandas 函数的兼容性? - 需要整数

c++ - 数组大小未定义? C++

excel - 同时将 2 个选定的相邻单元格的内容复制到表格的最后一行

基于在另一个表中查找代码和值的 Excel 总和

excel - 打开 Excel 文件时禁止显示错误消息

python - 多处理迭代器,过滤添加到双端队列的内容

python - 如何在Pygame中画一个小角度低速闪烁的移动圆圈?

python - 所有任务的单个工作线程还是多个特定的工作线程?

C: 将字节数组声明为 uint8_t 有什么问题吗?

php - 在 PHP 中使用 array_chunk 移动元素