I am trying to append a float number temp
to the list pChange
. However I get an error IndexError: list index out of range
The code works fine, except when I try to append to the list in pChange[j].append(temp)
def loadPrices(fn): #grabs prices from prices.txt
global nt, nInst
df = pd.read_csv(fn, sep='\s+', header=None, index_col=None)
nt, nInst = df.values.shape
return (df.values).T
pricesFile = "./prices.txt"
prcAll = loadPrices(pricesFile) #data stored in prcAll
pChange = [[]]*20
j = 0
print(pChange[j])
for stock in prcAll:
for i in range(1,5,1):
temp = prcAll[j][i] / prcAll[j][i-1]
pChange[j].append(temp)
#print(j)
j = j+1