This is the code that I am working with:
import pandas as pd
z = pd.Series(data = [1,2,3,4,5,6,7], index = xrange(1,8))
array = []
for i in range(1,8):
array.append(z[i]*2)
print array
It does exactly what I tell it to because I can't figure out how to do a simple iteration. This is the printed output
[2]
[2, 4]
[2, 4, 6]
[2, 4, 6, 8]
[2, 4, 6, 8, 10]
[2, 4, 6, 8, 10, 12]
[2, 4, 6, 8, 10, 12, 14]
What I want is for python to use the updated value in array so the desired output would be:
[2]
[2, 4]
[2, 4, 8]
[2, 4, 8, 16]
[2, 4, 8, 16, 32]
[2, 4, 8, 16, 32, 64]
[2, 4, 8, 16, 32, 64, 128]
Thank you for your help. Edit The example I first used was too simple so please answer using the example code below
import pandas as pd
sample = pd.Series(data = [ -3.2 , 30.66, 7.71, 9.87], index = range(0,4))
testarray = []
for i in range(0,4):
testarray.append(100000*(1+sample.values[i]/100))
print testarray
This produces
[96800.0, 130660.0, 107710.0, 109870.0]
When the desired numbers are: 96800 126478.88 136230.4016 149676.3423
So instead of it using 100000 I want it to use 96800 for the second iteration and so on. Thank you!