Brexit Data Analysis

British withdrawal from the European Union, often shortened to Brexit is a political goal that was pursued by various individuals, advocacy groups, and political parties since the United Kingdom (UK) joined the precursor of the European Union (EU) in 1973.


In [1]:
from __future__ import division
from bs4 import BeautifulSoup
import urllib2
import re
import string
In [2]:
# Scrape brexit data from BBC

areas = []
all_votes_leave = []
all_votes_remain = []
turnout_proportions = []

for letter in string.ascii_lowercase:
    try:
        response = urllib2.urlopen('http://www.bbc.co.uk/news/politics/eu_referendum/results/local/' + letter)
        html = response.read()
        soup = BeautifulSoup(html, "lxml")
    except:
        continue
    for results in soup.find_all(attrs={"class": "eu-ref-result-bar"}):
        area = results.find(attrs={"class": "eu-ref-result-bar__title"}).text
        tmp = results.find(attrs={"class": "eu-ref-result-bar__party eu-ref-result-bar__party--leave"})
        tmp = tmp.find(attrs={"class": "eu-ref-result-bar__votes"})
        tmp = re.sub('[a-zA-z, n]', '', tmp.text)
        votes_leave = int(tmp)
        tmp = results.find(attrs={"class": "eu-ref-result-bar__party eu-ref-result-bar__party--remain"})
        tmp = tmp.find(attrs={"class": "eu-ref-result-bar__votes"})
        tmp = re.sub('[a-zA-z, n]', '', tmp.text)
        votes_remain = int(tmp)
        tmp = results.find(attrs={"class": "eu-ref-result-bar__turnout"})
        tmp = re.sub('[a-zA-z, n%:]', '', tmp.text)
        turnout_proportion = float(tmp) / 100
        print(area, votes_leave, votes_remain, turnout_proportion)
        areas.append(area)
        all_votes_leave.append(votes_leave)
        all_votes_remain.append(votes_remain)
        turnout_proportions.append(turnout_proportion)
(u'Aberdeen City', 40729, 63985, 0.679)
(u'Aberdeenshire', 62516, 76445, 0.706)
(u'Adur', 20315, 16914, 0.764)
(u'Allerdale', 31809, 22429, 0.7290000000000001)
(u'Amber Valley', 44501, 29319, 0.763)
(u'Angus', 26511, 32747, 0.68)
(u'Argyll & Bute', 19202, 29494, 0.731)
(u'Arun', 56936, 34193, 0.778)
(u'Ashfield', 46720, 20179, 0.728)
(u'Ashford', 41472, 28314, 0.7709999999999999)
(u'Aylesbury Vale', 53956, 52877, 0.784)
(u'Babergh', 29933, 25309, 0.782)
(u'Barking & Dagenham', 46130, 27750, 0.638)
(u'Barnet', 60823, 100210, 0.721)
(u'Barnsley', 83958, 38951, 0.6990000000000001)
(u'Barrow-in-Furness', 21867, 14207, 0.6779999999999999)
(u'Basildon', 67251, 30748, 0.738)
(u'Basingstoke and Deane', 52071, 48257, 0.78)
(u'Bassetlaw', 43392, 20575, 0.748)
(u'Bath & North East Somerset', 44352, 60878, 0.7709999999999999)
(u'Bedford', 44569, 41497, 0.72)
(u'Belfast East', 21918, 20728, 0.665)
(u'Belfast North', 19844, 20128, 0.575)
(u'Belfast South', 13596, 30960, 0.6759999999999999)
(u'Belfast West', 8092, 23099, 0.489)
(u'Bexley', 80886, 47603, 0.752)
(u'Birmingham', 227251, 223451, 0.637)
(u'Blaby', 33583, 22888, 0.765)
(u'Blackburn with Darwen', 36799, 28522, 0.652)
(u'Blackpool', 45146, 21781, 0.654)
(u'Blaenau Gwent', 21587, 13215, 0.6809999999999999)
(u'Bolsover', 29730, 12242, 0.723)
(u'Bolton', 80491, 57589, 0.701)
(u'Boston', 22974, 7430, 0.772)
(u'Bournemouth', 50453, 41473, 0.6920000000000001)
(u'Bracknell Forest', 35002, 29888, 0.7609999999999999)
(u'Bradford', 123913, 104575, 0.667)
(u'Braintree', 52713, 33523, 0.7659999999999999)
(u'Breckland', 47235, 26313, 0.743)
(u'Brent', 48881, 72523, 0.65)
(u'Brentwood', 27627, 19077, 0.795)
(u'Bridgend', 40622, 33723, 0.711)
(u'Brighton & Hove', 46027, 100648, 0.74)
(u'Bristol', 87418, 141027, 0.731)
(u'Broadland', 42268, 35469, 0.7829999999999999)
(u'Bromley', 90034, 92398, 0.7879999999999999)
(u'Bromsgrove', 32563, 26252, 0.7929999999999999)
(u'Broxbourne', 33706, 17166, 0.737)
(u'Broxtowe', 35754, 29672, 0.7829999999999999)
(u'Burnley', 28854, 14462, 0.672)
(u'Bury', 54674, 46354, 0.713)
(u'Caerphilly', 53295, 39178, 0.7070000000000001)
(u'Calderdale', 58975, 46950, 0.71)
(u'Cambridge', 15117, 42682, 0.722)
(u'Camden', 23838, 71295, 0.654)
(u'Cannock Chase', 36894, 16684, 0.7140000000000001)
(u'Canterbury', 41879, 40169, 0.75)
(u'Cardiff', 67816, 101788, 0.696)
(u'Carlisle', 35895, 23788, 0.745)
(u'Carmarthenshire', 55381, 47654, 0.74)
(u'Castle Point', 37691, 14154, 0.753)
(u'Central Bedfordshire', 89134, 69670, 0.778)
(u'Ceredigion', 18031, 21711, 0.7440000000000001)
(u'Charnwood', 50672, 43500, 0.7040000000000001)
(u'Chelmsford', 53249, 47545, 0.7759999999999999)
(u'Cheltenham', 28932, 37081, 0.758)
(u'Cherwell', 41168, 40668, 0.755)
(u'Cheshire East', 113163, 107962, 0.773)
(u'Cheshire West and Chester', 98082, 95455, 0.745)
(u'Chesterfield', 34478, 22946, 0.7190000000000001)
(u'Chichester', 36326, 35011, 0.778)
(u'Chiltern', 26363, 32241, 0.835)
(u'Chorley', 36098, 27417, 0.755)
(u'Christchurch', 18268, 12782, 0.7929999999999999)
(u'City of London', 1087, 3312, 0.735)
(u'Clackmannanshire', 10736, 14691, 0.672)
(u'Colchester', 51305, 44414, 0.7509999999999999)
(u'Conwy', 35357, 30147, 0.7170000000000001)
(u'Copeland', 23528, 14419, 0.7)
(u'Corby', 20611, 11470, 0.741)
(u'Cornwall', 182665, 140540, 0.77)
(u'Cotswold', 26806, 28015, 0.7979999999999999)
(u'Coventry', 85097, 67967, 0.691)
(u'Craven', 18961, 16930, 0.81)
(u'Crawley', 31447, 22388, 0.732)
(u'Croydon', 78221, 92913, 0.698)
(u'Dacorum', 43702, 42542, 0.7909999999999999)
(u'Darlington', 30994, 24172, 0.71)
(u'Dartford', 35870, 19985, 0.755)
(u'Daventry', 28938, 20443, 0.809)
(u'Denbighshire', 28117, 23955, 0.691)
(u'Derby', 69043, 51612, 0.705)
(u'Derbyshire Dales', 24095, 22633, 0.8190000000000001)
(u'Doncaster', 104260, 46922, 0.695)
(u'Dover', 40410, 24606, 0.765)
(u'Dudley', 118446, 56780, 0.7170000000000001)
(u'Dumfries & Galloway', 38803, 43864, 0.7140000000000001)
(u'Dundee City', 26697, 39688, 0.629)
(u'Durham', 153877, 113521, 0.687)
(u'Ealing', 59017, 90024, 0.7)
(u'East Antrim', 22929, 18616, 0.652)
(u'East Ayrshire', 23942, 33891, 0.629)
(u'East Cambridgeshire', 24487, 23599, 0.77)
(u'East Devon', 48040, 40743, 0.789)
(u'East Dorset', 33702, 24786, 0.813)
(u'East Dunbartonshire', 17840, 44534, 0.7509999999999999)
(u'East Hampshire', 36576, 37346, 0.816)
(u'East Hertfordshire', 42994, 42372, 0.8029999999999999)
(u'East Lindsey', 56613, 23515, 0.7490000000000001)
(u'East Londonderry', 19455, 21098, 0.599)
(u'East Lothian', 19738, 36026, 0.7170000000000001)
(u'East Northamptonshire', 30894, 21680, 0.769)
(u'East Renfrewshire', 13596, 39345, 0.7609999999999999)
(u'East Riding of Yorkshire', 120136, 78779, 0.748)
(u'East Staffordshire', 39266, 22850, 0.743)
(u'Eastbourne', 30700, 22845, 0.747)
(u'Eastleigh', 39902, 36172, 0.782)
(u'Eden', 16911, 14807, 0.757)
(u'Edinburgh, City of', 64498, 187796, 0.7290000000000001)
(u'Eilean Siar', 6671, 8232, 0.701)
(u'Elmbridge', 31162, 45841, 0.7809999999999999)
(u'Enfield', 60481, 76425, 0.69)
(u'Epping Forest', 48176, 28676, 0.768)
(u'Epsom and Ewell', 21707, 23596, 0.804)
(u'Erewash', 40739, 25791, 0.76)
(u'Exeter', 28533, 35270, 0.738)
(u'Falkirk', 34271, 44987, 0.675)
(u'Fareham', 39525, 32210, 0.7959999999999999)
(u'Fenland', 37571, 15055, 0.737)
(u'Fermanagh & South Tyrone', 19958, 28200, 0.679)
(u'Fife', 75466, 106754, 0.667)
(u'Flintshire', 48930, 37867, 0.748)
(u'Forest Heath', 18160, 9791, 0.725)
(u'Forest of Dean', 30251, 21392, 0.774)
(u'Foyle', 8905, 32064, 0.574)
(u'Fylde', 26317, 19889, 0.755)
(u'Gateshead', 58529, 44429, 0.706)
(u'Gedling', 37542, 30035, 0.765)
(u'Gibraltar', 823, 19322, 0.835)
(u'Glasgow City', 84474, 168335, 0.562)
(u'Gloucester', 37776, 26801, 0.72)
(u'Gosport', 29456, 16671, 0.735)
(u'Gravesham', 35643, 18876, 0.7490000000000001)
(u'Great Yarmouth', 35844, 14284, 0.69)
(u'Greenwich', 52117, 65248, 0.695)
(u'Guildford', 34458, 44155, 0.769)
(u'Gwynedd', 25665, 35517, 0.723)
(u'Hackney', 22868, 83398, 0.6509999999999999)
(u'Halton', 37327, 27678, 0.682)
(u'Hambleton', 29502, 25480, 0.784)
(u'Hammersmith & Fulham', 24054, 56188, 0.6990000000000001)
(u'Harborough', 27850, 27028, 0.8140000000000001)
(u'Haringey', 25855, 79991, 0.705)
(u'Harlow', 29602, 13867, 0.735)
(u'Harrogate', 46374, 48211, 0.7879999999999999)
(u'Harrow', 53183, 64042, 0.722)
(u'Hart', 27513, 30282, 0.826)
(u'Hartlepool', 32071, 14029, 0.655)
(u'Hastings', 24339, 20011, 0.716)
(u'Havant', 44047, 26582, 0.741)
(u'Havering', 96885, 42201, 0.76)
(u'Herefordshire', 64122, 44148, 0.7829999999999999)
(u'Hertsmere', 28532, 27593, 0.7659999999999999)
(u'High Peak', 27717, 27116, 0.7559999999999999)
(u'Highland', 55349, 70308, 0.716)
(u'Hillingdon', 74982, 58040, 0.6890000000000001)
(u'Hinckley & Bosworth', 39501, 25969, 0.767)
(u'Horsham', 41303, 43785, 0.816)
(u'Hounslow', 56321, 58755, 0.6970000000000001)
(u'Huntingdonshire', 54198, 45729, 0.778)
(u'Hyndburn', 26568, 13569, 0.647)
(u'Inverclyde', 14010, 24688, 0.66)
(u'Ipswich', 38655, 27698, 0.725)
(u'Isle of Anglesey', 19333, 18618, 0.738)
(u'Isle of Wight', 49173, 30207, 0.723)
(u'Isles of Scilly', 621, 803, 0.792)
(u'Islington', 25180, 76420, 0.703)
(u'Kensington and Chelsea', 17138, 37601, 0.659)
(u'Kettering', 32877, 21030, 0.764)
(u"King's Lynn & West Norfolk", 56493, 28587, 0.747)
(u'Kingston upon Hull', 76646, 36709, 0.629)
(u'Kingston upon Thames', 32737, 52533, 0.7829999999999999)
(u'Kirklees', 118755, 98485, 0.7070000000000001)
(u'Knowsley', 36558, 34345, 0.635)
(u'Lagan Valley', 25704, 22710, 0.6659999999999999)
(u'Lambeth', 30340, 111584, 0.6729999999999999)
(u'Lancaster', 37309, 35732, 0.726)
(u'Leeds', 192474, 194863, 0.713)
(u'Leicester', 67992, 70980, 0.65)
(u'Lewes', 28508, 30974, 0.778)
(u'Lewisham', 37518, 86955, 0.63)
(u'Lichfield', 37214, 26064, 0.787)
(u'Lincoln', 24992, 18902, 0.693)
(u'Liverpool', 85101, 118453, 0.64)
(u'Luton', 47773, 36708, 0.662)
(u'Maidstone', 52365, 36762, 0.76)
(u'Maldon', 24302, 14529, 0.7909999999999999)
(u'Malvern Hills', 25294, 23203, 0.805)
(u'Manchester', 79991, 121823, 0.597)
(u'Mansfield', 39927, 16417, 0.726)
(u'Medway', 88997, 49889, 0.721)
(u'Melton', 17610, 12695, 0.813)
(u'Mendip', 32028, 33427, 0.769)
(u'Merthyr Tydfil', 16291, 12574, 0.674)
(u'Merton', 37097, 63003, 0.7340000000000001)
(u'Mid Devon', 25606, 22400, 0.7929999999999999)
(u'Mid Suffolk', 33794, 27391, 0.7809999999999999)
(u'Mid Sussex', 41057, 46471, 0.807)
(u'Mid Ulster', 16799, 25612, 0.617)
(u'Middlesbrough', 40177, 21181, 0.649)
(u'Midlothian', 17251, 28217, 0.6809999999999999)
(u'Milton Keynes', 67063, 63393, 0.736)
(u'Mole Valley', 25708, 29088, 0.821)
(u'Monmouthshire', 27569, 28061, 0.777)
(u'Moray', 23992, 24114, 0.674)
(u'Neath Port Talbot', 43001, 32651, 0.715)
(u'New Forest', 64541, 47199, 0.792)
(u'Newark and Sherwood', 40516, 26571, 0.768)
(u'Newcastle upon Tyne', 63598, 65405, 0.6759999999999999)
(u'Newcastle-under-Lyme', 43457, 25477, 0.743)
(u'Newham', 49371, 55328, 0.5920000000000001)
(u'Newport', 41236, 32413, 0.7020000000000001)
(u'Newry & Armagh', 18659, 31693, 0.637)
(u'North Antrim', 30938, 18782, 0.649)
(u'North Ayrshire', 29110, 38394, 0.6459999999999999)
(u'North Devon', 33100, 24931, 0.768)
(u'North Dorset', 23802, 18399, 0.797)
(u'North Down', 21046, 23131, 0.677)
(u'North East Derbyshire', 37235, 22075, 0.752)
(u'North East Lincolnshire', 55185, 23797, 0.679)
(u'North Hertfordshire', 35438, 42234, 0.782)
(u'North Kesteven', 42183, 25570, 0.784)
(u'North Lanarkshire', 59400, 95549, 0.609)
(u'North Lincolnshire', 58915, 29947, 0.7190000000000001)
(u'North Norfolk', 37576, 26214, 0.768)
(u'North Somerset', 64976, 59572, 0.774)
(u'North Tyneside', 60589, 52873, 0.723)
(u'North Warwickshire', 25385, 12569, 0.762)
(u'North West Leicestershire', 34969, 22642, 0.779)
(u'Northampton', 61454, 43805, 0.726)
(u'Northumberland', 96699, 82022, 0.743)
(u'Norwich', 29040, 37326, 0.691)
(u'Nottingham', 61343, 59318, 0.618)
(u'Nuneaton and Bedworth', 46095, 23736, 0.743)
(u'Oadby & Wigston', 17173, 14292, 0.737)
(u'Oldham', 65369, 42034, 0.679)
(u'Orkney Islands', 4193, 7189, 0.6829999999999999)
(u'Oxford', 20913, 49424, 0.723)
(u'Pembrokeshire', 39155, 29367, 0.7440000000000001)
(u'Pendle', 28631, 16704, 0.7020000000000001)
(u'Perth and Kinross', 31614, 49641, 0.737)
(u'Peterborough', 53216, 34176, 0.723)
(u'Plymouth', 79997, 53458, 0.7140000000000001)
(u'Poole', 49707, 35741, 0.753)
(u'Portsmouth', 57336, 41384, 0.703)
(u'Powys', 42707, 36762, 0.77)
(u'Preston', 34518, 30227, 0.687)
(u'Purbeck', 16966, 11754, 0.789)
(u'Reading', 31382, 43385, 0.725)
(u'Redbridge', 59020, 69213, 0.675)
(u'Redcar & Cleveland', 48128, 24586, 0.7020000000000001)
(u'Redditch', 28579, 17303, 0.752)
(u'Reigate & Banstead', 40980, 40181, 0.782)
(u'Renfrewshire', 31010, 57119, 0.6920000000000001)
(u'Rhondda Cynon Taf', 62590, 53973, 0.674)
(u'Ribble Valley', 20550, 15892, 0.79)
(u'Richmond upon Thames', 33410, 75396, 0.82)
(u'Richmondshire', 15691, 11945, 0.7509999999999999)
(u'Rochdale', 62014, 41217, 0.659)
(u'Rochford', 34937, 17510, 0.7879999999999999)
(u'Rossendale', 23169, 15012, 0.7240000000000001)
(u'Rother', 33753, 23916, 0.7929999999999999)
(u'Rotherham', 93272, 44115, 0.695)
(u'Royal Borough of Windsor and Maidenhead', 37706, 44086, 0.797)
(u'Rugby', 33199, 25350, 0.79)
(u'Runnymede', 24035, 20259, 0.76)
(u'Rushcliffe', 29888, 40522, 0.815)
(u'Rushmoor', 28396, 20384, 0.741)
(u'Rutland', 11613, 11353, 0.7809999999999999)
(u'Ryedale', 17710, 14340, 0.772)
(u'Salford', 62385, 47430, 0.632)
(u'Sandwell', 98250, 49004, 0.665)
(u'Scarborough', 37512, 22999, 0.73)
(u'Scottish Borders', 26962, 37952, 0.7340000000000001)
(u'Sedgemoor', 41869, 26545, 0.763)
(u'Sefton', 71176, 76702, 0.7170000000000001)
(u'Selby', 30532, 21071, 0.7909999999999999)
(u'Sevenoaks', 38258, 32091, 0.8059999999999999)
(u'Sheffield', 136018, 130735, 0.6729999999999999)
(u'Shepway', 37729, 22884, 0.7490000000000001)
(u'Shetland Islands', 5315, 6907, 0.703)
(u'Shropshire', 104166, 78987, 0.773)
(u'Slough', 29631, 24911, 0.621)
(u'Solihull', 68484, 53466, 0.76)
(u'South Antrim', 22055, 21498, 0.634)
(u'South Ayrshire', 25241, 36265, 0.698)
(u'South Bucks', 20647, 20077, 0.78)
(u'South Cambridgeshire', 37061, 56128, 0.812)
(u'South Derbyshire', 34216, 22479, 0.768)
(u'South Down', 15625, 32076, 0.624)
(u'South Gloucestershire', 83405, 74928, 0.762)
(u'South Hams', 26142, 29308, 0.802)
(u'South Holland', 36423, 13074, 0.753)
(u'South Kesteven', 49424, 33047, 0.782)
(u'South Lakeland', 30800, 34531, 0.797)
(u'South Lanarkshire', 60024, 102568, 0.653)
(u'South Norfolk', 41541, 38817, 0.785)
(u'South Northamptonshire', 30771, 25853, 0.794)
(u'South Oxfordshire', 37865, 46245, 0.807)
(u'South Ribble', 37318, 26406, 0.753)
(u'South Somerset', 56940, 42527, 0.7859999999999999)
(u'South Staffordshire', 43248, 23444, 0.778)
(u'South Tyneside', 49065, 30014, 0.682)
(u'Southampton', 57927, 49738, 0.6809999999999999)
(u'Southend-on-Sea', 54522, 39348, 0.728)
(u'Southwark', 35209, 94293, 0.6609999999999999)
(u'Spelthorne', 34135, 22474, 0.779)
(u'St Albans', 32237, 54208, 0.8240000000000001)
(u'St Edmundsbury', 35224, 26986, 0.767)
(u'St Helens', 54357, 39322, 0.688)
(u'Stafford', 43386, 34098, 0.778)
(u'Staffordshire Moorlands', 38684, 21076, 0.753)
(u'Stevenage', 27126, 18659, 0.737)
(u'Stirling', 15787, 33112, 0.74)
(u'Stockport', 77930, 85559, 0.7390000000000001)
(u'Stockton-on-Tees', 61982, 38433, 0.71)
(u'Stoke-on-Trent', 81563, 36027, 0.657)
(u'Strangford', 23383, 18727, 0.645)
(u'Stratford-on-Avon', 40817, 38341, 0.8079999999999999)
(u'Stroud', 33618, 40446, 0.8)
(u'Suffolk Coastal', 41966, 37218, 0.8059999999999999)
(u'Sunderland', 82394, 51930, 0.648)
(u'Surrey Heath', 26667, 25638, 0.7979999999999999)
(u'Sutton', 57241, 49319, 0.76)
(u'Swale', 47388, 28481, 0.742)
(u'Swansea', 61936, 58307, 0.695)
(u'Swindon', 61745, 51220, 0.758)
(u'Tameside', 67829, 43118, 0.66)
(u'Tamworth', 28424, 13705, 0.741)
(u'Tandridge', 27169, 24251, 0.8029999999999999)
(u'Taunton Deane', 34789, 30944, 0.7809999999999999)
(u'Teignbridge', 44363, 37949, 0.7929999999999999)
(u'Telford & Wrekin', 56649, 32954, 0.721)
(u'Tendring', 57447, 25210, 0.7440000000000001)
(u'Test Valley', 39091, 36170, 0.7959999999999999)
(u'Tewkesbury', 28568, 25084, 0.7909999999999999)
(u'Thanet', 46037, 26065, 0.728)
(u'The Vale of Glamorgan', 35628, 36681, 0.7609999999999999)
(u'Three Rivers', 27097, 25751, 0.784)
(u'Thurrock', 57765, 22151, 0.727)
(u'Tonbridge & Malling', 41229, 32792, 0.7959999999999999)
(u'Torbay', 47889, 27935, 0.736)
(u'Torfaen', 28781, 19363, 0.698)
(u'Torridge', 25200, 16229, 0.7829999999999999)
(u'Tower Hamlets', 35224, 73011, 0.645)
(u'Trafford', 53018, 72293, 0.758)
(u'Tunbridge Wells', 29320, 35676, 0.7909999999999999)
(u'Upper Bann', 27262, 24550, 0.638)
(u'Uttlesford', 26324, 25619, 0.802)
(u'Vale of White Horse', 33192, 43462, 0.8109999999999999)
(u'Wakefield', 116165, 58877, 0.711)
(u'Walsall', 92007, 43572, 0.696)
(u'Waltham Forest', 44395, 64156, 0.6659999999999999)
(u'Wandsworth', 39421, 118463, 0.7190000000000001)
(u'Warrington', 62487, 52657, 0.733)
(u'Warwick', 33642, 47976, 0.792)
(u'Watford', 23419, 23167, 0.716)
(u'Waveney', 41290, 24356, 0.726)
(u'Waverley', 31601, 44341, 0.823)
(u'Wealden', 52808, 44084, 0.8)
(u'Wellingborough', 25679, 15462, 0.754)
(u'Welwyn Hatfield', 31060, 27550, 0.75)
(u'West Berkshire', 44977, 48300, 0.799)
(u'West Devon', 18937, 16658, 0.812)
(u'West Dorset', 33267, 31924, 0.794)
(u'West Dunbartonshire', 16426, 26794, 0.639)
(u'West Lancashire', 35323, 28546, 0.7440000000000001)
(u'West Lindsey', 33847, 20906, 0.745)
(u'West Lothian', 36948, 51560, 0.6759999999999999)
(u'West Oxfordshire', 30435, 35236, 0.797)
(u'West Somerset', 13168, 8566, 0.7909999999999999)
(u'West Tyrone', 13274, 26765, 0.618)
(u'Westminster', 24268, 53928, 0.649)
(u'Weymouth and Portland', 23352, 14903, 0.758)
(u'Wigan', 104331, 58942, 0.6920000000000001)
(u'Wiltshire', 151637, 137258, 0.7879999999999999)
(u'Winchester', 29886, 42878, 0.812)
(u'Wirral', 83069, 88931, 0.7090000000000001)
(u'Woking', 24214, 31007, 0.774)
(u'Wokingham', 42229, 55272, 0.8)
(u'Wolverhampton', 73798, 44138, 0.675)
(u'Worcester', 29114, 25125, 0.738)
(u'Worthing', 32515, 28851, 0.754)
(u'Wrexham', 41544, 28822, 0.715)
(u'Wychavon', 44201, 32188, 0.8079999999999999)
(u'Wycombe', 45529, 49261, 0.757)
(u'Wyre', 40163, 22816, 0.746)
(u'Wyre Forest', 36392, 21240, 0.74)
(u'York', 45983, 63617, 0.706)
In [3]:
# Tally up votes

total_votes_leave = sum(all_votes_leave)
total_votes_remain = sum(all_votes_remain)
percent_brexit = total_votes_leave / (total_votes_leave + total_votes_remain)

print(percent_brexit)
0.518922595696
In [4]:
# Create adjusted votes - what if there had been 100% turnout with same percentage of leave / remain in each area

adjusted_all_votes_leave = [votes / prop for votes, prop in zip(all_votes_leave, turnout_proportions)]
adjusted_all_votes_remain = [votes / prop for votes, prop in zip(all_votes_remain, turnout_proportions)]

adjusted_total_votes_leave = sum(adjusted_all_votes_leave)
adjusted_total_votes_remain = sum(adjusted_all_votes_remain)
adjusted_percent_brexit = adjusted_total_votes_leave / (adjusted_total_votes_leave + adjusted_total_votes_remain)

print(adjusted_percent_brexit)
0.517143339465
I hope this tutorial will surely help you. If you have any questions or problems please let me know.


Happy Hadooping with Patrick..
             


Leave a Reply

Your email address will not be published. Required fields are marked *