Commit e5e5d70c by Isaac Wink

Merge branch 'master' of mit.cs.uchicago.edu:ajfriedman/election_district_drawing

parents 781ce5d6 21c370a4
Showing with 18 additions and 5 deletions
......@@ -4,15 +4,18 @@ import csv
def create_json_file(dictionary, path_file_name):
tract_str = str(dictionary)
if type(dictionary) != str:
tract_str = str(dictionary)
if type(dictionary) == str:
tract_str = dictionary
with open(path_file_name + ".json", 'w') as json_file:
json.dump(tract_str, json_file)
def recover_json(json_file):
with open(json_file) as json_tracts:
str_tracts = json.load(json_tracts)
dict_tracts = ast.literal_eval(str_tracts)
return dict_tracts
with open(json_file) as json_tracts:
str_tracts = json.load(json_tracts)
dict_tracts = ast.literal_eval(str_tracts)
return dict_tracts
def read_csv(path, file_name):
with open(path + file_name) as csvfile:
......@@ -22,3 +25,13 @@ def read_csv(path, file_name):
num_districts_states[row['state']] = row['num']
return num_districts_states
def color_csv(path, file_name):
with open(path + file_name) as csvfile:
colors_dict = {}
reader = csv.DictReader(csvfile)
count = 1
for row in reader:
colors_dict[count] = row['colors']
count += 1
return colors_dict
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment