python - PyTables batch get and update -
i have daily stock data hdf5 file created using pytables. group of rows, process array , write disk (update rows) using pytables. couldn't figure out way cleanly. please let me know best way accomplish this?
my data:
symbol, date, price, var1, var2 abcd, 1, 2.5, 12, 12.5 abcd, 2, 2.6, 11, 10.2 abcd, 3, 2.45, 11, 10.3 defg, 1,12.34, 19.1, 18.1 defg, 2, 11.90, 19.5, 18.2 defg, 3, 11.75, 21, 20.9 defg, 4, 11.74, 22.2, 21.4
i read rows correspond each symbol array, processing , update fields var1 , var2. know symbols in advance can loop through them. tried this:
rows_array = [row.fetch_all_fields() row in table.where('symbol == "abcd"')]
i pass rows_array function compute values var1 , var2 , update each record. please note var1, var2 moving averages not able calculate them inside iterator , hence need entire set of rows array.
after calculate whatever need using rows_array, not sure how write data i.e., update rows new calculated values. when updating entire table , use this:
table.cols.var1[:] = calc_something(rows_array)
however, when want update portion of table, not best way it. guess can re-run 'where' condition , update each row based on calcs that's seems waste of time rescanning table.
your suggestions appreciated...
thanks, -e
if understand well, next should want:
condition = 'symbol == "abcd"' indices = table.getwherelist(condition) # indices rows_array = table[indices] # values new_rows = compute(rows_array) # compute new values table[indices] = new_rows # update indices new values
hope helps
Comments
Post a Comment