Turn PEI Election Results into Machine-Readable Data

Peter Rukavina

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.

Comments

Submitted by anonymous on

Permalink

How do you account for the advance polls? Greens lost 22 or 23 of the advance polls, which is represented by each polling area. Can you do a map by advance polls as well?

Unfortunately advance poll count is published on a district-by-district level (despite all of the voters in the advance polls having “home” polls that they’re attached to by their civic address).

So it’s only be possible to produce advance polls results maps on a district level, not a poll level. Here’s what it looks like:

Map showing advance poll winners

This map is deceptive because it includes polling division boundaries — the province hasn’t yet released a GIS layer that includes only district boundaries (and trying to combined the polling division polygons in QGIS to produce district polygons leaves some annoying leftover bits).

Which is to say that what’s represented on this map are “what districts did each party win the advance poll in”. It’s not a poll-level visualization.

Hey Peter, found this post searching for PEI GIS electoral boundaries. I've been trying to combine the 2017 poll polygons in QGIS to having a district map, it's driving me mad. Happy to read I am not the only one having this problem.

Add new comment

Plain text

  • Allowed HTML tags: <b> <i> <em> <strong> <blockquote> <code> <ul> <ol> <li>
  • Lines and paragraphs break automatically.

About This Blog

Photo of Peter RukavinaI am . I am a writer, letterpress printer, and a curious person.

To learn more about me, read my /nowlook at my bio, listen to audio I’ve posted, read presentations and speeches I’ve written, or get in touch (peter@rukavina.net is the quickest way). 

You can subscribe to an RSS feed of posts, an RSS feed of comments, or a podcast RSS feed that just contains audio posts. You can also receive a daily digests of posts by email.

Search