Last active
November 3, 2020 22:00
-
-
Save hoffrocket/a3d382dc2eccad16861d737fe30b2195 to your computer and use it in GitHub Desktop.
538 Election predictions to TSV
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
from urllib import request | |
import json | |
all_votes = json.load(request.urlopen("https://projects.fivethirtyeight.com/2020-election-forecast/states_electoral_votes.json")) | |
predictions = json.load(request.urlopen("https://projects.fivethirtyeight.com/2020-election-forecast/state_summary.json"))[0]["states"] | |
predictions.sort(key=lambda p: p["state"]) | |
for prediction in predictions: | |
state = prediction["state"] | |
vote_count = next(v["votes"] for v in all_votes if v["state"] == state) | |
# not an endorsement! | |
trump_prob = next(c["winprob"]/100 for c in prediction["candidates"] if c["candidate"] == "Trump") | |
print(f"{state}\t{vote_count}\t{trump_prob}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment