0
votes

I have the following command below:

import pandas as pd
import numpy as np
from scipy import stats
np.random.seed(12345)

standarderrors1992 = stats.sem(np.random.normal(32000,200000,3650))
standarderrors1993 = stats.sem(np.random.normal(43000,100000,3650))
standarderrors1994 = stats.sem(np.random.normal(43500,140000,3650))
standarderrors1995 = stats.sem(np.random.normal(48000,70000,3650)) 
mean1992 = np.random.normal(32000,200000,3650).mean()
mean1993 = np.random.normal(43000,100000,3650).mean()
mean1994 = np.random.normal(43500,140000,3650).mean()
mean1995 = np.random.normal(48000,70000,3650).mean()

Here, I have found both the mean and standard error for a set of randomly chosen values.

limit = 3000
dict = {mean1992:standarderrors1992,mean1993:standarderrors1993,mean1994:standarderrors1994,mean1995:standarderrors1995} 
for key,value in dict:
    if limit > (key+(1.96*value)):
    colour = 1 
    elif limit < (key+(1.96*value)):
    colour = 0 
    elif (limit !> (key+(1.96*value))) && (limit !< (key-(1.96*value))):
    colour = ((key+(1.96*value))-limit)/((key+(1.96*value))-(key-(1.96*value)))

Here, I am trying to put the values corresponding to the means and standard errors into a dictionary so that I can loop through both of them.

Ideally, I want to assign a particular value to the variable 'colour' depending on the values for the mean and standard error of a particular year. i.e. mean and SE for 1992

However, I keep getting the error:

TypeError: cannot unpack non-iterable int object

Coudld anyone let me know where I'm going wrong?

1

1 Answers

2
votes

You need to iterate over dict.items() for this to work.

for key,value in dict.items():
    # do stuff here

I would advice against naming your variables dict which shadows the build in dict function though :)