【发布时间】:2013-12-16 21:08:29
【问题描述】:
我有一个包含浮点数的大型 numpy 数组,我使用 np.savetxt("myFile.csv", myArray, delimiter=",") 将其保存为 csv 文件
现在,由于数组有很多列并且很难记住是什么,我想在导出之前向数组添加一个字符串标题。既然 numpy 不接受浮点数组中的字符串,那么有什么技巧可以做到这一点吗?
[解决方案] 感谢 Cyborg 的建议,我成功地安装了 Pandas。
import pandas as pd
df = pd.DataFrame(A) # A is a numpy 2d array
df.to_excel("A.xls", header=C,index=False) # C is a list of string corresponding to the title of each column of A
【问题讨论】:
标签: arrays numpy header pandas export-to-csv