-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_csvs.py
More file actions
45 lines (33 loc) · 1.14 KB
/
Copy pathparse_csvs.py
File metadata and controls
45 lines (33 loc) · 1.14 KB
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
import csv, json
from collections import OrderedDict
def go_through_data(c,info,counties):
for row in c:
if row['STNAME'] not in info:
info[row['STNAME']] = {}
counties[row['STNAME']] = {}
n = row['CTYNAME'].decode('latin-1')
if n not in info[row['STNAME']]:
#print info
#print row['CTYNAME']
#print n
counties[row['STNAME']][n] = ''
info[row['STNAME']][n] = []
new_person = {}
new_person['sex'] = int(row['SEX'])
new_person['his'] = int(row['ORIGIN'])
new_person['age'] = int(row['AGEGRP'])
new_person['race'] = int(row['IMPRACE'])
#new_person['res_pop'] = row['RESPOP']
info[row['STNAME']][n].append(new_person)
f1 = open('stco-mr2010_al_mo.csv','r')
f2 = open('stco-mr2010_mt_wy.csv','r')
info = OrderedDict()
counties = OrderedDict()
c1 = csv.DictReader(f1)
c2 = csv.DictReader(f2)
go_through_data(c1,info,counties)
go_through_data(c2,info,counties)
with open('demographics.json','w') as dt:
json.dump(info,dt)
with open('counties.json','w') as dt:
json.dump(counties,dt)