在python中保存带有列标题的矩阵

时间:2015-11-14 15:47:20

标签: python numpy import

我有以下代码。当我保存它。列标题不保存。你可以指导我吗?

import numpy as np
import pandas as pd

A = np.random.randint(0, 10, size=36).reshape(6, 6)

df = pd.DataFrame(A,  columns=['one', 'two', 'three','four','five','six'])
np.savetxt("/home/dataset/test.csv",df, delimiter=",")

1 个答案:

答案 0 :(得分:0)

使用内置pandas功能:

df.to_csv("your_file_path_here")