append elements into the empty dataframe - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: append elements into the empty dataframe (/thread-13059.html) |
append elements into the empty dataframe - jazzy - Sep-26-2018 def backtest(inCapital): rCapital = inCapital qty1 = 0 hp = 0 cap=0 preAdjClose = 0 tempAdjClose = 0 columns = ['Date'] #, 'AdjClose', 'POS', 'SMA' ,'LMA'] df = pdd.DataFrame(columns=columns) for i in range(len(data)): if hp == 0: if data['short_moving_emavg'][i] > data['long_moving_emavg'][i]: hp = 1 tempAdjClose = preAdjClose preAdjClose = data['Adj Close'][i] pd = data['Adj Close'][i] - preAdjClose qty=100 pnl = qty * pd rCapital = rCapital + pnl print(data['Date'][i] +' | '+ str(data['Adj Close'][i]) +' | '+ str(tempAdjClose) +' | '+ str(hp) +' | '+ str(data['short_moving_emavg'][i]) +' | '+ str(data['long_moving_emavg'][i])+' | '+ str(pd)+' | '+ str(qty) +' | '+ str(pnl) +' | '+str(rCapital) ) continue I want to convert this output into dataframe. I tried appending elements but did not work
|