如何使用标题

时间:2015-10-14 12:39:38

标签: python-2.7 pandas

我有一个DataFrame - pd(如下所示),我想写一个文本文件,我成功地能够用pd.to_csv()命令将它写入csv,但是当我把它写入一个文本文件我得到没有任何标题或索引的数据。如何包含标题和索引?

 NIST       CG100       CG050  FactoryCal  HMFW (nm)     Sigma   WCalDer
0   605.613  826.487904  826.373969  826.058347   1.425848  1.120941  1.851244
1   587.092  790.587148  790.580384  790.194184   1.376891  1.202015  2.055721
2   690.468  953.660187  953.438435  952.582371   1.874943  0.968623  1.216525
3   681.311  942.452371  942.143394  941.144706   1.630595  0.877735  1.267568
4   431.958  214.029705  214.030983  214.347893   0.711980  2.019422  6.679031
5   665.223  921.620793  921.463130  919.973594   2.804547  1.626438  1.365617
6   450.235  325.734244  325.722302  325.772933   0.738286  1.750162  5.582228
7   557.029  722.478884  722.471888  722.337452   1.491010  1.561811  2.466618
8   427.397  183.088318  183.032558  178.288276   0.752349  2.237605  7.003544
9   669.923  928.331440  928.155865  926.308634   3.186223  1.807440  1.335801
10  645.629  893.315870  893.430749  892.083966   1.174274  0.748784  1.501554

用于写入文本文件的命令。

  

np.savetxt(os.path.join(new_directory,base_filename2),pd,fmt ='%d')

0 个答案:

没有答案