@Ekinydre gave you a good solution, but I just wanted to elaborate on the error you got.
When you have a list like change_array = [1, 2, 3], then change_array[i] accessed element i (lists use 0-based indices in Python). Also, += in Python is not an append operator, but an increment operator. So change_array[i] += 10 you are adding 10 to the list element at position i.
You could just append to change_array as @Ekinydre suggests, but given your code it may be safer (though less pythonic) to do something like the following:
#define variables for a loop
#create a list of 0 of length end_year_index
change_array = [0]*end_year_index
roc = 0
#iterate to find the change percentage
for i in range (0, end_year_index+1):
if i == 0:
change_array[i] += 0
else:
roc = ((population[i] - population[i-1])/ (population[i-1]))
change_array[i] += roc
A slightly more pythonic way could look like this:
change_array = [(population[i] - population[i-1]) / population[i-1] \
for i in range(1, end_year_index+1)]
Note: this last solution won't have the initial 0 at the beginning of change_array.
change_arrayshould be[0 for _ in range(end_year_index+1)], if you want there to be a zero to add to at each index. You can't index arbitrarily into a Python list, or at all with an empty list.change_arraya dictionary.defaultdict(int), certainly.change_arrayto contain initially as you have not defined it in the code above?