如何在python/numpy中創建一個文本文件,並排顯示多個1D數組,並排對齊列(即用空格分隔)。我還想在列的頂部包含數組的名稱。Python/Numpy - 將多個1D數組寫入整齊列中的文件
這是一個我一直在使用的例子。 (請注意,在一個字符串[「現場」]數組是不同的字符的長度,從而導致不對齊列)
import numpy as np
dt = np.dtype([('site', '|S11'), ('year', 'i'), ('dat1', 'd'), ('dat2', 'd')])
a = np.zeros(2, dt)
a['site'] = ['Paris', 'London']
a['year'] = [1979, 1980]
a['dat1'] = [272.4322, 270.36]
a['dat2'] = [2.21, 3.55]
np.savetxt('test.txt', a, '%s')
理想我想的東西,可以產生這樣的文件:http://www.antarctica.ac.uk/data/absl/ABSL-index-Monthly-ERA-Interim_Hosking2013.txt
我現在已經找到了一個答案的問題,請參見下面的... https://stackoverflow.com/a/19676112/1310153
你應該看看:[熊貓](http://pandas.pydata.org/) [to_csv](http://pandas.pydata.org/pandas-docs/stable/generated /pandas.DataFrame.to_csv.html?highlight=to_csv#pandas.DataFrame.to_csv) 您可以將數組放入'Series' =>到'DataFrame'中,然後放到一個csv文件中。 或嘗試設置'np.savetxt('test.txt',a,fmt ='%s',delimiter ='\ t') –
https://code.google.com/p/prettytable/可能會訣竅與調整 – wim
你可以給一個輸出的例子? – Christian