Skip to content

Instantly share code, notes, and snippets.

@michalskop
Last active June 9, 2017 02:20
Show Gist options
  • Save michalskop/1553c1483151bf1422fa to your computer and use it in GitHub Desktop.
Save michalskop/1553c1483151bf1422fa to your computer and use it in GitHub Desktop.
CZ: Local elections 2014
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.
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