Last active
June 9, 2017 02:20
-
-
Save michalskop/1553c1483151bf1422fa to your computer and use it in GitHub Desktop.
CZ: Local elections 2014
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 | |
from operator import itemgetter | |
import csv | |
with open("cz2014towns.json") as infile: | |
results = json.load(infile) | |
data = {} | |
datatotal = {} | |
for town in results: | |
for row in town['votes']: | |
try: | |
data[row['name']] | |
except: | |
data[row['name']] = 0 | |
try: | |
datatotal[row['name']] | |
except: | |
datatotal[row['name']] = 0 | |
data[row['name']] += row['result']/100 * town['population'] | |
datatotal[row['name']] += town['population'] | |
with open("parties_votes.csv","w") as ofile: | |
csvw = csv.writer(ofile) | |
for key in data: | |
csvw.writerow([key,data[key],datatotal[key]]) | |
This file has been truncated, but you can view the full file.
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
View raw
(Sorry about that, but we can’t show files that are this big right now.)
View raw
(Sorry about that, but we can’t show files that are this big right now.)
View raw
(Sorry about that, but we can’t show files that are this big right now.)
View raw
(Sorry about that, but we can’t show files that are this big right now.)
View raw
(Sorry about that, but we can’t show files that are this big right now.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment