Skip to content

Instantly share code, notes, and snippets.

@gunnarig
Created October 8, 2018 23:10
Show Gist options
  • Save gunnarig/ccd0d67b1e9e32276348f3166e98321f to your computer and use it in GitHub Desktop.
Save gunnarig/ccd0d67b1e9e32276348f3166e98321f to your computer and use it in GitHub Desktop.
import string
from itertools import cycle
def get_word_string(user_file):
user_file = open(user_file,"r")
states = []
#wordString = '' # start with an empty string of words
lines = user_file.readlines()
header = lines[0].split(",")
#TODO: REMOVE NEWLINE
states.append(header)
for line in lines[1:]:
items = line.split(",")
state = items[0]
stripped_items = []
for item in items[1:]:
item = item.strip('\n')
if item == 'N/A':
item = None
else:
item = float(item.strip("%"))
stripped_items.append(item)
states.append(tuple([state, stripped_items]))
#print(states)
return states
def combine_colums(a_list):
stats_list = []
item = [item[0] for item in a_list]
stats_list.append(item)
print(stats_list)
def combine_illness_max(a_list, col):
illness = [item[1][col] for item in a_list[1:]]
#print(illness)
max_value = max(illness)
state = ''
for i in range(len(illness)):
if illness[i] == max_value:
state = a_list[i+1][0]
break
return tuple([state, max_value])
def combine_illness_min(a_list, col):
illness = [item[1][col] for item in a_list[1:]]
#print(illness)
min_value = min(illness)
state = ''
for i in range(len(illness)):
if illness[i] == min_value:
state = a_list[i+1][0]
break
return tuple([state, min_value])
def pretty_print(stuff):
print("Indicator Min Max ")
print("---------------------------------------------------------------------------------------")
heart_min = combine_illness_min(stuff, 0)
heart_max = combine_illness_max(data, 0)
mvd_min = combine_illness_min(stuff, 5)
mvd_max = combine_illness_max(data,5)
print(stuff[0][1]+":"+str(heart_min[0])+" "+str(heart_min[1])+" "+str(heart_max[0])+ " "+str(heart_max[1]))
print(stuff[0][5]+":"+str(mvd_min[0])+" "+str(mvd_min[1])+" "+str(mvd_max[0])+ " "+str(mvd_max[1]))
print(stuff[0][1]+":"+str(heart_min[0])+" "+str(heart_min[1])+" "+str(heart_max[0])+ " "+str(heart_max[1]))
print(stuff[0][1]+":"+str(heart_min[0])+" "+str(heart_min[1])+" "+str(heart_max[0])+ " "+str(heart_max[1]))
print(stuff[0][1]+":"+str(heart_min[0])+" "+str(heart_min[1])+" "+str(heart_max[0])+ " "+str(heart_max[1]))
return
'''
Heart Disease Death Rate (2007): Hawaii 140.3 Minnesota 429.8
Motor Vehicle Death Rate (2009): District of Columbia 4.8 Wyoming 24.6
Teen Birth Rate (2009): Mississippi 14.2 New Mexico 63.9
Adult Smoking (2010): Utah 9.1 West Virginia 26.8
Adult Obesity (2010): District of Columbia 22.7 Colorado 81.4
'''
def scramble_string(words):
return words
#filename = input("Enter name of file: ")
filename = 'riskFactors.csv'
data = get_word_string(filename)
#combine_colums(data, 1)
pretty_print(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment