Skip to content

Instantly share code, notes, and snippets.

@michalskop
michalskop / calc3_2.py
Last active January 2, 2016 10:29
CZ Presidential Elections '13: Voters' transfers (research)
# -*- coding: utf-8 -*-
# calculates the transfers, 2 rounds
# using weights from R
import json
import csv
# read into data
i = 0
@michalskop
michalskop / calc4.py
Last active January 2, 2016 13:19
CZ Presidential Elections: 4+ and 2- votes (stacked chart)
# -*- coding: utf-8 -*-
#
#
import pickle
import csv
import json
with open("responsesw", 'rb') as f:
@michalskop
michalskop / csv2json.php
Last active January 2, 2016 23:59
CZ Senate Elections; 2014 (Winners in Polling Station)
<?php
//join election results with list of all stations and output lat,lng,results into json
// we want to get such structure (similar):
// {"name": "\u00dast\u00ed nad Labem-0", "winner": "Zeman", "coordinates": ["14.036975", "50.660316"], "id": "554804-0", "population": {"p9": "16025", "p6": "21011", etc. }, "party" : {"p1": "Úsvit", etc. }, "names": ["p1": "Talaš ..", etc.}},
$handle_results = fopen('zlin_stations.csv','r');
$handle_geo = fopen('okrsky_geo_adj.csv','r');
$handle_out = fopen('zlin.json','w');
// read results
@michalskop
michalskop / index.html
Last active January 3, 2016 20:29
Weighted PCA Model in R
We couldn’t find that file to show.
@michalskop
michalskop / csv2json.php
Last active January 3, 2016 23:19
Senate Elections 2014, Zlín, 2nd Round
<?php
//join election results with list of all stations and output lat,lng,results into json
// we want to get such structure (similar):
// {"name": "\u00dast\u00ed nad Labem-0", "winner": "Zeman", "coordinates": ["14.036975", "50.660316"], "id": "554804-0", "population": {"p9": "16025", "p6": "21011", etc. }, "party" : {"p1": "Úsvit", etc. }, "names": ["p1": "Talaš ..", etc.}},
$handle_results = fopen('zlin_stations.csv','r');
$handle_geo = fopen('okrsky_geo_adj.csv','r');
$handle_out = fopen('zlin.json','w');
// read results
@michalskop
michalskop / csv2json_sankey.py
Last active January 4, 2016 01:49
Senate Elections 2014, Zlín; Ecological Inference using Regression
# -*- coding: utf-8 -*-
# creates json for sankey from matrix row->column
# 10 -> 3
import json
import csv
# read into data
out = {}
@michalskop
michalskop / csv2json.py
Last active August 29, 2015 13:56
El Salvador, Presidential Elections 2014, 1st Round
# -*- coding: utf-8 -*-
import json
import csv
import string
data = []
i = 0
with open("geocoded_adj.csv","r") as fin:
finreader = csv.reader(fin,delimiter="\t")
@michalskop
michalskop / ex1.csv
Last active August 29, 2015 13:56
Inner circles seem bigger than outer rings (experiment)
name S A D F group white
Person-1 5 15 50 95 3 0
Person-2 5 30 80 98 3 0
Person-3 2 20 50 90 3 0
Person-4 1 10 50 98 3 0
Person-5 12 24 78 95 3 0
Person-6 5 10 65 98 3 0
Person-7 1 12 65 97 3 0
Person-8 5 20 68.5 94 3 0
Person-9 10 20 50 90 3 0
@michalskop
michalskop / README.md
Last active May 28, 2019 02:53
SK: Comparison of presidential candidates 2014
@michalskop
michalskop / README.md
Last active August 29, 2015 13:56
SK: Spatial distribution of presidential candidates 2014