Plotting a referendum - Sourcing data
Following the shock decision by the UK to leave the EU, many ideas were put forward as to the reasons behind why so many people voted the ways that they did.
In an effort to learn more about data handling in python, using pandas, matplotlib and other fun stuff I scoured the internet for data and set about plotting graphs.
Before playing around with the data, we first must get hold of it. This meant a large amount of seraching around and trying to piece together datasets from the vast number of government websites, each with different formats, styles and ideas.
The python scripts all assume that the files downloaded here are in a
subdirectory raw
.
CAP data
The CAP spending data is required to be freely available by the EU. There is a dedicated website for this, which provides an online lookup as well as an option to download the data.
Go to the download page and grab the 2015 dataset.
Map info
The CAP data is stored by postcode, rather than by voting ward. As such we need to grab the postcode information to link each postcode back to the voting ward it lies in.
The point data for the centers of all UK postcodes is available as part of
Ordnance Survey’s Open Data scheme, so head over to
their website.
Here we need their Code-Point Open
data and while you’re there you should also
get their Boundary-Line
data as a ESRI Shapefile
.
The Boundary-Line data is the shapefile containing polygons of all the electoral and administrative boundaries across the country. We will be using the District Electoral boundaries to draw the maps.
Immigration data
The Office for National Statistics provides immigration data split into local areas. This dataset is huge, with much more than we need, but is the best I could find.
Go here and download the excel file.
Referendum results
The Electoral Commission released the EU referendum results online, available here, so grab the full dataset.
Nomis - unemployment and income
The best source for data on income and unemployment by local area was from the Office for National Statistic’s Nomis website, which provides a range of data on the UK labour markets. We need to download two sets of data:
Dataset | Claimant count → Claimant count by sex and age |
Geography | local authorities: district / unitary (as of April 2015) |
Date | May 2016 |
Age | All (16+) |
Rates | Claimant count AND Claimants as a proportion of residents aged 16-64 |
Sex | Total |
Include Area codes |
Rename the resulting file nomis-unemployment.csv
.
Dataset | Annual Survey of Hours and Earnings → annual survey of hours and earnings - resident analysis |
Geography | local authorities: district / unitary (as of April 2015) |
Date | 2015 |
Pay and hours | Annual pay - gross |
Sex & full/part-time | full-time workers |
Variable | median |
Include Area codes |
Rename the resulting file nomis-media-income.csv
.