French presidential election of 2012

The results of the french presidential elections in 2012 are available on the home office website. Unfortunately the data can only be accessed through a huge amount of clicking. Thus I wrote a small script in perl which takes care of all these clicks ,gathers the results for each individual city and strores them in a file. (You can find less precise data here)

For information, you can download the script. It does not work anymore because the website was changed since then, nevertheless correcting the script should be quite straightforward. This script allowed me to download the detailled results for every city in France which you can download here : data_pres.zip. It is a compressed CSV file which contains for every city and both of the two rounds : the number of people inscribed, votes, abstentions, blank or invalids as well as the number of votes for each candidate.

To produce nice maps, we need to know the coordinates of the cities. They can be easily found on the web, for example on this site. I also seized the opportunity to add some socioeconomic data about these cities all of them being available on the INSEE website. All the data are compiled by another script in a file similar to the previous one available here : data_pres_geo.zip.

We can then use a software like TileMill to draw maps of the results. Below is a map showing the results of the second round, each marker is a city and its size represents the number on inhabitants. The red markers are the cities where François Hollande was first and the blue markers are the cities where Sarkozy received more votes.

Some geographical regions are obviously mainly right wing (Sarkozy -- blue) whereas others are much more left wing (Hollande -- red). You can also see that Hollande won in most of the big cities, it is particularly clear in Alsace (North-East) where the only two red dots are the largest cities Strasbourg and Mulhouse.

These data can also be more precisely analyzed in order to find correlations between the votes for the different candidates, or these votes could be correlated with socioeconomic data. I leave this to experts in statistics.

I was very proud of myself after these long hours scraping websites for data, making maps,... But I should have taken a little more time searching on the net (what I did writing this page) because all these data are already available on the data-publica.fr website, and as usual, a guy mush better than me had already made all this ! (And much better than me)