I am having trouble iterating across an entire dictionary to do simple summary statistics (an average) for each element of a value across keys.
My dictionary consists of keys and values that are lists of numbers:
test_dict={'NJ':[20,50,70,90,100],'NY':[10,3,0,99,57],'CT':[90,1000,2,3.4,5]}
I know that I can access the first value of each key, for instance, by doing the below, but I am having trouble with the obvious next step of adding another for loop to iterate across all elements in the values.
location1=[element[0] for element in test_dict.values()]
location1_avg=sum(location1)/len(location1)
My ultimate goal is to have a dictionary with labels as keys (Location 1...i) and the average value across states for that location. So the first key-value would be Location1: 40, and so on.
I have the below attempt, but the error message is 'list index out of range' and i do not know how to iterate properly in this case.
for element in test_dict.values():
avg=list()
for nums in element[i]:
avg[i]=sum(element[i][nums])/len(element[i][nums])
Adding desired output per requests
soln_dict={'Location1':40,'Location2':351,'Loction3':24,'Loction4':43.24,'Loction5':54}
Thank you for your help!