Quantcast
Channel: ruk.ca - Peter Rukavina's Weblog
Viewing all articles
Browse latest Browse all 4349

Turn PEI Election Results into Machine-Readable Data

$
0
0

Elections PEI published results of yesterday’s provincial general election as a collection of HTML tables, which are not well-suited when you’re looking for machine-readable data to do interesting things with. Things like this visualization of the winners of each poll:

Visualization of the winners of every poll in the April 23, 2019 provincial general election

Or this visualization of the party that came second place in every poll:

Visualization showing which party came SECOND PLACE in every poll

Or this visualization of polls where Green candidates came first or second:

Map showing polls where Greens came first OR second

Fortunately, HTML tables are sort of machine-readable to start, and it doesn’t table much to parse them and turn them into something even more machine-readable.

So this morning I wrote some code to do exactly that, and you can download it and take it for a ride or, if you’re just looking for the data itself you can grab one of two files:

It’s that “winners” file that I used to create the visualization above, which you can explore in an interactive version that I’ve just published to the QGIS Cloud.

I combined the CSV file with the Electoral Districts GIS layer. To be able to do this I first needed to create “virtual field” called “distpoll” in the Electoral Districts layer:

Screen shot showing virtual field.

With that virtual field in place, I could join the winners CSV file to the Electoral Districts layer, using the “distpoll” field for the join:

Screen shot showing how the two files are joined.

And with the files joined, I used “rule-based” styles in QGIS to colour-code each poll by the winner (leaving those polls with no winner–those in District 9 in this case, where the election was delayed–white):

Styling the polls by poll winner.

I’m hopeful that others can build on this code to make additional interesting things from the results.


Viewing all articles
Browse latest Browse all 4349

Trending Articles