Skip to content
Browse files

join

  • Loading branch information...
1 parent d953e89 commit 95f21394e42738644aeb6bbf21c4e0746d9b987e @tlevine committed Feb 25, 2013
Showing with 20 additions and 1 deletion.
  1. +1 −0 collect/president-2012/county.json
  2. +19 −1 collect/president-2012/parse.py
View
1 collect/president-2012/county.json
1 addition, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
20 collect/president-2012/parse.py 100644 → 100755
@@ -1,7 +1,25 @@
#!/usr/bin/env python2
import json
+# Load the two tables
county_shapes = json.load(open('county-shapes.json'))
county_results = json.load(open('county-results.json'))
-#county['objects']['president'][county_shape['objects'][0]['pr']['f']]
+# Which keys are missing from one of the tables?
+shape_ids = set([o['pr']['f'] for o in county_shapes['objects']])
+result_ids = set(county_results['objects']['president'].keys())
+missing = shape_ids.symmetric_difference(result_ids)
+
+print('Data are missing for these counties, so I am skipping them.')
+print(', '.join(missing))
+
+for o in county_shapes['objects']:
+ shape_id = o['pr']['f']
+
+ # Skipp the missing ones.
+ if shape_id in missing:
+ continue
+
+ o['results'] = county_results['objects']['president'][shape_id]
+
+json.dump(county_shapes['objects'], open('county.json', 'w'))

0 comments on commit 95f2139

Please sign in to comment.
Something went wrong with that request. Please try again.