2013-07-25 43 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"