Created
November 6, 2019 04:07
-
-
Save laurelmay/872c55e82c9e50b9c20c3c261fc3dc45 to your computer and use it in GitHub Desktop.
Benford's Law w/ VA Election Data
This file contains hidden or 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
#!/usr/bin/env python3 | |
import json | |
import requests | |
url = "https://results.elections.virginia.gov/vaelections/2019%20November%20General/Json/GeneralAssembly.json" | |
results = {} | |
for i in range(1, 10): | |
results[str(i)] = 0 | |
data = requests.get(url).json() | |
for race in data['Races']: | |
for candidate in race['Candidates']: | |
# This forces the data to an integer (just in case we got some weird floating point | |
# number), and ensures that if the first digit is 0, the number itself is 0 | |
first = str(int(candidate['Votes']))[0] | |
if first == '0': | |
continue | |
results[first] += 1 | |
print(json.dumps(results, indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment