2013-07-25 44 views
2

我有csv文件中的股票價格數據和我的生活我無法弄清楚爲什麼批量插入不起作用。我創建recarray有以下類型insert_records稱爲:pytables appending recarray

[('id', 'O'), ('dt', '<i8'), ('adj_dt', '<i8'), ('currency', 'O'), ('close', '<f8'), ('open', '<f8'), ('high', '<f8'), ('low', '<f8'), ('volume', '<f8')] 

我創建了一個表列:

OHLCTableDescription = {'id': tables.StringCol(10), 
         'dt': tables.Int64Col(), 
         'adj_dt': tables.Int64Col(), 
         'currency': tables.StringCol(5), 
         'open': tables.Float64Col(dflt=np.NaN), 
         'high': tables.Float64Col(dflt=np.NaN), 
         'low': tables.Float64Col(dflt=np.NaN), 
         'close': tables.Float64Col(dflt=np.NaN), 
         "volume": tables.Float64Col(dflt=np.NaN)} 

這個工程:

for row in insert_records: 
    current_row = table.row 
    dtype = insert_records.dtype.names 
    for j in range(len(dtype)): 
     current_row[dtype[j]] = row[j] 
     current_row.append() 

,這並不:

table.append(insert_records) 

我得到這個錯誤

ValueError("rows parameter cannot be converted into a recarray object compliant with table '/TD/date_20130102 (Table(0,), shuffle, zlib(9)) '20130102''. The error was: <Cannot change data-type for object array.>",) 
rows parameter cannot be converted into a recarray object compliant with table '/TD/date_20130102 (Table(0,), shuffle, zlib(9)) '20130102''. The error was: <Cannot change data-type for object array.> 

這是什麼錯誤是指什麼?

回答

0

python對象不能用於追加到pytables。 pytables需要確切的recarray數據類型。

如果更改了dtype,這將會附加。

dtype[0] = "|S14"