Index: trunk/tools/wsor/scripts/convert_congress_districts_from_flat_files.py |
— | — | @@ -0,0 +1,39 @@ |
| 2 | +from __future__ import division |
| 3 | +import sys |
| 4 | + |
| 5 | +valid_zip = r'[0-9]{5}' |
| 6 | + |
| 7 | +#read in FIPS |
| 8 | +fips_dict = {} |
| 9 | +fips_file = open ("FIPS2AB.txt") |
| 10 | +fip_line = fips_file.readline() |
| 11 | +while fip_line: |
| 12 | + fips_data = fip_line.split("\t") |
| 13 | + fips_code = fips_data[1].strip() |
| 14 | + fips_state = fips_data[2].strip() |
| 15 | + fips_dict[fips_code] = fips_state |
| 16 | + fip_line = fips_file.readline() |
| 17 | + |
| 18 | +#ZIP convert |
| 19 | +zip_dict = {} |
| 20 | +zip_file = open ("zcta_cd111_rel_10.txt") |
| 21 | +zip_line = zip_file.readline() #header |
| 22 | +zip_line = zip_file.readline() |
| 23 | +while zip_line: |
| 24 | + zip_data = zip_line.split(",") |
| 25 | + zip_code = zip_data[0] |
| 26 | + state = "XX" |
| 27 | + if( zip_data[1] in fips_dict): |
| 28 | + state = fips_dict[zip_data[1]] |
| 29 | + |
| 30 | + dist = zip_data[2] |
| 31 | + if(zip_code not in zip_dict): |
| 32 | + zip_dict[zip_code] = [] |
| 33 | + zip_dict[zip_code].append(state+"_"+dist) |
| 34 | + zip_line = zip_file.readline() |
| 35 | + |
| 36 | +for zipline in zip_dict: |
| 37 | + for district in zip_dict[zipline]: |
| 38 | + print zipline, district, 1/len(zip_dict[zipline]) |
| 39 | + |
| 40 | + |
Property changes on: trunk/tools/wsor/scripts/convert_congress_districts_from_flat_files.py |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 41 | + native |