Published
Edited
Sep 22, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
scrutini = d3.csv("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/scrutiniCI_cm.csv")
Insert cell
Insert cell
Insert cell
Insert cell
comuniViminaleISTAT = d3.csv("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/risorse/comuniViminaleISTAT.csv")
Insert cell
comuniViminaleISTAT_ = Data.import({"source":comuniViminaleISTAT,"type":"json"})
Insert cell
Inputs.Table(comuniViminaleISTAT_.json())
Insert cell
Insert cell
camera_geopolitico = d3.csv("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/camera_geopolitico_italia.csv")
Insert cell
camera_geopolitico_ = Data.import({"source":camera_geopolitico,"type":"json"})
Insert cell
Insert cell
Insert cell
gen_procomMapA = function() {
var procomMapA = [];
procomMapA["TORINO - PIEMONTE 1 - 01 - 01"] = 1272;
procomMapA["TORINO - PIEMONTE 1 - 01 - 02"] = 1272;
procomMapA["TORINO - PIEMONTE 1 - 01 - 03"] = 1272;
procomMapA["TORINO - PIEMONTE 1 - 01 - 04"] = 1272;
procomMapA["MILANO - LOMBARDIA 1 - 02 - 09"] = 15146;
procomMapA["MILANO - LOMBARDIA 1 - 03 - 08"] = 15146;
procomMapA["MILANO - LOMBARDIA 1 - 03 - 11"] = 15146;
procomMapA["MILANO - LOMBARDIA 1 - 03 - 12"] = 15146;
procomMapA["MILANO - LOMBARDIA 1 - 03 - 13"] = 15146;
procomMapA["MILANO - LOMBARDIA 1 - 03 - 14"] = 15146;
procomMapA["GENOVA - LIGURIA - 01 - 03"] = 10025;
procomMapA["GENOVA - LIGURIA - 02 - 04"] = 10025;
procomMapA["GENOVA - LIGURIA - 02 - 05"] = 10025;
procomMapA["BOLOGNA - EMILIA-ROMAGNA - 03 - 06"] = 37006;
procomMapA["BOLOGNA - EMILIA-ROMAGNA - 03 - 07"] = 37006;
procomMapA["FIRENZE - TOSCANA - 03 - 01"] = 48017;
procomMapA["FIRENZE - TOSCANA - 03 - 02"] = 48017;
procomMapA["ROMA - LAZIO 1 - 01 - 01"] = 58091;
procomMapA["ROMA - LAZIO 1 - 01 - 02"] = 58091;
procomMapA["ROMA - LAZIO 1 - 01 - 03"] = 58091;
procomMapA["ROMA - LAZIO 1 - 01 - 04"] = 58091;
procomMapA["ROMA - LAZIO 1 - 01 - 05"] = 58091;
procomMapA["ROMA - LAZIO 1 - 01 - 06"] = 58091;
procomMapA["ROMA - LAZIO 1 - 01 - 08"] = 58091;
procomMapA["ROMA - LAZIO 1 - 01 - 09"] = 58091;
procomMapA["ROMA - LAZIO 1 - 01 - 10"] = 58091;
procomMapA["ROMA - LAZIO 1 - 01 - 11"] = 58091;
procomMapA["ROMA - LAZIO 1 - 02 - 06"] = 58091;
procomMapA["ROMA - LAZIO 1 - 02 - 08"] = 58091;
procomMapA["ROMA - LAZIO 1 - 02 - 09"] = 58091;
procomMapA["ROMA - LAZIO 1 - 02 - 10"] = 58091;
procomMapA["ROMA - LAZIO 1 - 02 - 11"] = 58091;
procomMapA["ROMA - LAZIO 1 - 03 - 07"] = 58091;
procomMapA["NAPOLI - CAMPANIA 1 - 02 - 05"] = 63049;
procomMapA["NAPOLI - CAMPANIA 1 - 02 - 06"] = 63049;
procomMapA["NAPOLI - CAMPANIA 1 - 02 - 07"] = 63049;
procomMapA["NAPOLI - CAMPANIA 1 - 02 - 08"] = 63049;
procomMapA["BARI - PUGLIA - 01 - 01"] = 72006;
procomMapA["BARI - PUGLIA - 01 - 02"] = 72006;
procomMapA["PALERMO - SICILIA 1 - 01 - 01"] = 82053;
procomMapA["PALERMO - SICILIA 1 - 01 - 02"] = 82053;
procomMapA["PALERMO - SICILIA 1 - 01 - 03"] = 82053;

return procomMapA;
}
Insert cell
procomMapA = gen_procomMapA();
Insert cell
Insert cell
Insert cell
scrutini_LI = scrutini_.select("WHERE tipo_riga == LI");

Insert cell
Inputs.Table(scrutini_LI.json())
Insert cell
Insert cell
procomA = comuniViminaleISTAT_.lookupArray("PRO_COM","ELIGENDO_C_UID_CI");

Insert cell
nomeA = camera_geopolitico_.lookupArray("nome","id");
Insert cell
Insert cell
scrutini_LI_1 = scrutini_LI.addColumn({source:'codice',destination:'nome'},
function(codice){
return (camera_geopolitico_.lookup(codice,{value:"nome",lookup:"id"}));
});

Insert cell
Inputs.Table(scrutini_LI_1.json())

Insert cell
Insert cell
scrutini_LI_2 = scrutini_LI_1.addColumn({source:'codice',destination:'pro_com'},
function(value){
if ( typeof(procomA[value]) != "undefined" ){
return (procomA[value]);
}else{
// codice not found in comuniViminaleISTAT.csv (città metropolitane)
// then map to name and lookup in my list procomMapA[]
return procomMapA[nomeA[value]];
}
});

Insert cell
Insert cell
scrutini_LI_3 = scrutini_LI_2.addColumn({source:'pro_com',destination:'nome_lower'},
function(pro_com){
return (comuniViminaleISTAT_.lookup(pro_com,{value:"COMUNE",lookup:"PRO_COM"}));
});

Insert cell
Inputs.Table(scrutini_LI_3.json())
Insert cell
Insert cell
pivot = scrutini_LI_3.pivot({
lead: 'codice',
keep: ['pro_com','nome','nome_lower'],
cols: 'descr_lista',
value: "voti"
});

Insert cell
Insert cell
pivot_final = pivot.condense({lead:'pro_com',keep:['codice','pro_com']});

Insert cell
Inputs.Table(pivot_final.json())
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more