python pandas set_value not persistent? -


i'm trying write small program in python keeping track of equity portfolio on year, registering every buy/sell, , keeping track of balance. i'm going through list of orders , update pandas dataframe, keep portfolio. code looks pretty obscure i'm quite new pandas/numpy:

orders_book = dataframe(np.zeros((num_of_days,num_of_companies+1)), ldt_timestamps, columns = book_keys)  equity_sym in ls_symbols[1:2]:     trade_date in ldt_timestamps:         if trade_date == ldt_timestamps[0]:             current_number = orders_book.xs(trade_date)[equity_sym]         transaction in trades:             transaction_date = transaction[0]             transaction_sym  = transaction[1]             if ( ( trade_date == transaction_date ) , (equity_sym == transaction_sym ) ):                 transaction_order  = transaction[2]                 transaction_number =  transaction[3]                 if str(transaction_order) == 'buy':                     current_number += transaction_number                 if str(transaction_order) == 'sell':                     current_number -= transaction_number         orders_book.ix[trade_date,equity_sym, current_number] = current_number 

[equity_sym] kept comments convince printing in runtime checked complicated loop works ok (as see, update orders_book using set_value). however, when loop ends, , try print orders_book['goog'], orders_book looks @ beginning, i.e., before loop. why that? appreciate :)

edit: code changed , works properly. not panda's fault wrong placement of updating/writing function in code. effort!

according this answer pandas' author, set_value returns reference new object. need use concat or append add rows data table. see section "merge, join, , concatenate" in pandas manual.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -