Skip to content

Instantly share code, notes, and snippets.

@mapmeld
Created January 20, 2024 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapmeld/e5d89a75fd41b1234167625a4c35200c to your computer and use it in GitHub Desktop.
Save mapmeld/e5d89a75fd41b1234167625a4c35200c to your computer and use it in GitHub Desktop.
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