Created
January 20, 2024 18:53
-
-
Save mapmeld/e5d89a75fd41b1234167625a4c35200c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
j = json.load(open('./census-reviewed.json', 'r')) | |
headers = None | |
total_vars = { | |
'P1_047N': 0, | |
'P1_063N': 0, | |
'P1_070N': 0, | |
'P2_072N': 0, | |
'Hisp': 0, | |
} | |
sort_by_state = [] | |
# national totals | |
for line in j: | |
if headers is None: | |
headers = line | |
continue | |
for key in total_vars.keys(): | |
if key == 'Hisp': | |
six_plus = int(line[ headers.index('P1_070N') ]) - int(line[ headers.index('P2_072N') ]) | |
total_vars[key] += six_plus | |
pop = float(line[ headers.index('P1_001N')]) | |
four_plus = int(line[ headers.index('P1_047N') ]) + int(line[ headers.index('P1_063N') ]) + int(line[ headers.index('P1_070N') ]) | |
sort_by_state.append({ | |
'state': line[ headers.index('state') ], | |
'all': six_plus, | |
'all_cap': six_plus / pop, | |
'six': int(line[ headers.index('P1_070N') ]), | |
'six_cap': float(line[ headers.index('P1_070N') ]) / pop, | |
'four_plus': four_plus, | |
'four_plus_cap': four_plus / pop, | |
}) | |
else: | |
total_vars[key] += int(line[ headers.index(key) ]) | |
print(total_vars) | |
print(sorted(sort_by_state, key=lambda s: s['all_cap'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment