2016-10-21 44 views
0

我加載了一個csv文件,並使用標題指定每列的名稱。是否可以在numpy.genfromtxt輸出中添加新字段?

# Load the Data 
data = np.genfromtxt('dat_h.csv', 
        delimiter=',', 
        names=True) 

這很好,因爲我可以通過名字訪問列。例如...

DATES = data['Dates'] 
Temperature = data['Temp'] 

說我有一個與這些測量值相匹配的壓力觀測值向量。我可以在數據結構中添加一個包含壓力變量的新字段嗎?

我想要做這樣的事情...

data.append('Pressure',pressure_vector) 
# and then be able to access that field like I do the other fields 
data['Pressure'] 

回答

2

查找到this answer。這裏是用於recfunctions的docs

主要是我想你需要的是這樣的:

from numpy.lib.recfunctions import append_fields 

append_fields(data, 'Pressure', pressure_vector, np.double) 
相關問題