-
Notifications
You must be signed in to change notification settings - Fork 2
/
csv_data.py
79 lines (67 loc) · 2.92 KB
/
csv_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import csv
import statistics
import json
def get_min_max_std(lst):
minimum = min(lst)
maximum = max(lst)
std_dev = statistics.stdev(lst)
return minimum, maximum, std_dev
with open('POINTS_MASTER.csv') as f:
code_list = f.read().split()
code_set = set(code_list)
code_dict = {}
for el in code_set:
code_dict[el] = {}
income_list = []
econ_active = []
population = []
with open("data/economic_activity.csv", 'rU') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['code'] in code_set:
code_dict[row['code']]['activity'] = float(row['opacity'])
with open("data/income.csv", 'rU') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['code'] in code_set:
code_dict[row['code']]['income_low'] = float(row['income_low'])
code_dict[row['code']]['income'] = float(row['income'])
code_dict[row['code']]['income_mid'] = float(row['income_middle'])
code_dict[row['code']]['income_high'] = float(row['income_high'])
with open("data/ethnicity.csv", 'rU') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['code'] in code_set:
population.append(float(row['population']))
code_dict[row['code']]['population'] = float(row['population'])
with open("data/gender.csv", 'rU') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['code'] in code_set:
code_dict[row['code']]['male'] = float(row['male_opacity'])
code_dict[row['code']]['female'] = float(row['female_opacity'])
with open("data/gender.csv", 'rU') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['code'] in code_set:
code_dict[row['code']]['male'] = float(row['male_opacity'])
code_dict[row['code']]['female'] = float(row['female_opacity'])
with open("data/age.csv", 'rU') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['code'] in code_set:
code_dict[row['code']]['age0to12'] = float(row['age0to12'])
code_dict[row['code']]['age13to18'] = float(row['age13to18'])
code_dict[row['code']]['age19to25'] = float(row['age19to25'])
code_dict[row['code']]['age26to40'] = float(row['age26to40'])
code_dict[row['code']]['age41to60'] = float(row['age41to60'])
code_dict[row['code']]['age61to90'] = float(row['age61to90'])
with open("data/ethnicity.csv", 'rU') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['code'] in code_set:
code_dict[row['code']]['white'] = float(row['white_opacity'])
code_dict[row['code']]['indian'] = float(row['indian_opacity'])
code_dict[row['code']]['chinese'] = float(row['chinese_opacity'])
code_dict[row['code']]['black'] = float(row['black_opacity'])
print(json.dumps(code_dict))