# Was it the PC party's election to lose?

Posted in civics on Saturday, May 09 2015

I've been hearing a lot that this past election was the PC party's to lose, and that what we saw was not an "Orange Crush" as much as an ABC -- Anything But Conservative. I'm not sure entirely how you would test this with data, but one I think I could do is look at who is the biggest loser.

This is also an excuse to break out geopandas and start making maps! Hooray maps! As with before I loaded the election data straight from the Alberta elections website and processed it. I indexed the table by election district number this time, just for convenience. Then I processed the data with the addition of who was the runner up.

The results of this is a table with the votes for each party, the total number of votes, the difference between the winner and the next runner up, which party was the winner, which party was the runner up, and if we lived in a two-party state which party would win.

Super conveniently, Alberta elections has a shapefile for all the election districts which you can download. Unfortunately for later the shapefile is in some weird I don't know what and not latitude and longitude (I know nothing about GIS y'all!) so it isn't straight forward to make a google map or something (or maybe it is? I know nothing about GIS y'all!). I load this as another dataframe, and again I index it by election district number.

Now I know that row 1 of the election results corresponds to row 1 of the shape data. This is handy.

I can make a nice rainbow plot of the election districts using matplotlib, hey that's my home province!

Now I can walk through my table of election results and colour code a map based on who won, I don't know if my colours are the party colours, I just picked them by eye as being "orange" or "blue".

But who were the biggest losers?

I can just as well make a map of all the runners up. There's a lot of blue on that map.

As you can see from the bar-charts below, the PC party was the biggest loser, the runner up in the most ridings. Which really drives home that the PC base did not desert them completely, just that enough not conservatives showed up and that sealed the deal.

Finally, for completeness here's what it would have looked like if the NDP had absorbed all the left wing parties and the PCs all the right wing parties (well, the Wildrose party). The NDP would have still done well in Edmonton and Calgary, but the province would have been solidly blue once more.

As I mentioned before, the units in the shape file from Alberta Elections means nothing to me so I don't know how to plot it on one of the many javascript mapping tools out there (think google maps), which typially require latitude and longitude. This is bad as a lot of ridings are hard to see on those maps above, lots of people live in the cities which appear as tiny flecks compared to the large rural ridings. It would be nice if people could zoom and pan around the map.

Bokeh provides a nice set of generic javascript plotting tools, accessible from python, so I can output a map like the ones above but with the ability to pan and zoom. Here is a map showing the runner up to each district.

Broadly it appears that the cities were a battle mostly between the NDP and PCs, and the rural ridings, well, mostly PC/WRP except in the north where the NDP made a good showing.