Example #1
0
h=f.readline().strip().split(",")

# Initialize 53 empty lists
s=[]
for i in range(53):
    s.append([])

# Loop over the remaining lines
for l in f:

    # Create a list by separating the line at commas
    d=l.split(",")

    # Store the 53 entries in the line to each relevant list
    for i in range(53):
        s[i].append(d[i])

# Close the file
f.close()

# Check correlations with Massachusetts score
q=[]
for i in range(2,53):
    q.append((h[i],correl(s[i],s[1])))

# Sort the list
p=sorted(q, key=itemgetter(1), reverse=True)

# Formatted output
for j in p:
    print "%20s : %7.5f" % j
Example #2
0
# Close the file
f.close()


c = []

#Initialize 51 empty lists
for i in range(51):
    c.append([])

#Iterate over all of the lists calculating correlations 
# between each pair of states    
for i in range(2,53):
   for j in range(2,53):
        if (i != j):
            c[i - 2].append((h[j],correl(s[i],s[j])))


# Sort the lists
for i in range(51):
    t = sorted(c[i], key=itemgetter(1), reverse=True)
    
    #for now I only want the top 3 for each state
    p = t[:3] #list of 3 tuples
    for k in range(3):
        [name, r] = p[k] 
        v = h.index(name) - 2 
        p[k] = [v , r]
    c[i] = p
    
# http://www.cdc.gov/flu/fluvaxview/reports/reporti1213/reporti/index.htm