Graph election results


In [1]:
import os
import numpy as np
import pandas as pd
import geopandas as gpd
import folium

import matplotlib
%matplotlib inline

In [2]:
from splitters import Splitters
from parsing_utils import parse_eleccions_2015_csv, collapse_votes, collapse_info_mesas, left_filter_function

In [3]:
par_splits = {'n_splits': 10, 'limits': (0, 1),
              'open_limits': True, 'reverse': False}
splitter = Splitters('equispaced_splitters', par_splits, ranges=None)

In [4]:
splitter(0.5)


Out[4]:
6

In [5]:
file_geojson = '/home/tono/code/Eleccions2017Cat/data/trio_llobregat.geojson'
data_censo = gpd.read_file(file_geojson)

In [6]:
(data_censo['CUMUN'] == '08073').sum()


Out[6]:
70

In [7]:
data_censo['CUSEC'] = data_censo['CUSEC'].apply(lambda x: str(x))

In [39]:
#pro_ind = pd.DataFrame([data_censo['CUSEC'].as_matrix(), np.random.random(len(data_censo))]).T
#pro_ind.rename(columns={0: 'CUSEC', 1: 'Pro_ind'}, inplace=True)
g = data_censo.loc[data_censo['CUDIS'] == '0807301', 'geometry'].unary_union
type(g)
data_censo.columns


Out[39]:
Index([  u'OBJECTID',      u'CUSEC',      u'CUMUN',       u'CSEC',
             u'CDIS',       u'CMUN',       u'CPRO',        u'CCA',
            u'CUDIS',        u'OBS',      u'CNUT0',      u'CNUT1',
            u'CNUT2',      u'CNUT3',      u'CLAU2',       u'NPRO',
              u'NCA',       u'NMUN', u'Shape_Leng', u'Shape_area',
        u'Shape_len',   u'geometry'],
      dtype='object')

In [43]:
class GeoDataCensal(object):

    def __init__(self, data_censal, var_hierarchy):
        self._check_inputs(data_censal, var_hierarchy)
        self.data_censal = data_censal
        self.var_hierarchy = var_hierarchy
        self.levels = len(var_hierarchy['codes'])

    def _check_inputs(self, data_censal, var_hierarchy):
        assert('geometry' in var_hierarchy)
        assert('codes' in var_hierarchy)
        assert('names' in var_hierarchy)
        assert(isinstance(var_hierarchy['geometry'], str))
        assert(isinstance(var_hierarchy['codes'], list))
        assert(isinstance(var_hierarchy['names'], list))
        assert(len(var_hierarchy['codes']) == len(var_hierarchy['names']))

    def _get_columns_level(self, level, outer=False):
        outer_cols = []
        if outer:
            outer_cols = self.outer_cols
        geo_cols = [self.var_hierarchy['geometry']]
        if level == 0:
            columns = outer_cols+geo_cols
        elif level > self.levels or level < 0:
            msg = "Not correct 'level' input."
            raise IndexError(msg)
        else:
            names_cols = self.var_hierarchy['names'][self.levels-level:]
            codes_cols = self.var_hierarchy['codes'][self.levels-level:]
            columns = list(set(outer_cols+names_cols+codes_cols+geo_cols))
        return columns

    def _filter4level(self, level, outer=False):
        return self.data_censal[self._get_columns_level(level, outer)]

    @classmethod
    def _data_reduction(cls, data_censo, var_hierarchy):
        return cls(data_censo, var_hierarchy)

    @property
    def inner_cols(self):
        inner_cols = [var_hierarchy['geometry']]
        inner_cols += var_hierarchy['codes']
        inner_cols += var_hierarchy['names']
        inner_cols = list(set(inner_cols))
        return inner_cols

    @property
    def outer_cols(self):
        outer_cols = [col for col in self.data_censal
                      if col not in self.inner_cols]
        return outer_cols

    def _filter_censo_by_level(self, level, outer=False):
        data_censo = self._filter4level(level, outer)
        pivot_lvl_col = self.var_hierarchy['codes'][self.levels-level]
        data = data_censo.dissolve(by=pivot_lvl_col).reset_index(level=0)
        return data

    def _filter_hierharchy_by_level(self, level):
        var_hierarchy = {}
        var_hierarchy['geometry'] = self.var_hierarchy['geometry']
        pivot_lvl = self.levels-level
        var_hierarchy['codes'] = self.var_hierarchy['codes'][pivot_lvl:]
        var_hierarchy['names'] = self.var_hierarchy['names'][pivot_lvl:]
        return var_hierarchy

    def filter_data_by_level(self, level, outer=False, raw=False):
        data_censo = self._filter_censo_by_level(level, outer)
        var_hierarchy = self._filter_hierharchy_by_level(level)
        if raw:
            return data_censo, var_hierarchy
        else:
            return self._data_reduction(data_censo, var_hierarchy)

In [58]:
var_hierarchy = {
    'names': ['CUSEC', 'CUDIS', 'NMUN', 'NPRO', 'NCA'],
    'codes': ['CUSEC', 'CUDIS', 'CUMUN', 'CPRO', 'CCA'],
    'geometry': 'geometry'
}
datacensal = GeoDataCensal(data_censo, var_hierarchy)

datacensal.filter_data_by_level(5, False).data_censal


Out[58]:
CUSEC geometry CPRO NMUN CUMUN NCA CCA CUDIS NPRO
0 0807301001 POLYGON ((2.07086332857145 41.35740405853809, ... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
1 0807301002 POLYGON ((2.070671819595459 41.35602864763179,... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
2 0807301003 POLYGON ((2.077546728450129 41.35071454754457,... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
3 0807301004 POLYGON ((2.049558400975442 41.34744746709448,... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
4 0807301005 POLYGON ((2.076844113283871 41.35191659116927,... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
5 0807301006 POLYGON ((2.072357123758789 41.35348683736885,... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
6 0807301007 POLYGON ((2.071632524362656 41.35349974731189,... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
7 0807301008 POLYGON ((2.067353723362825 41.35395055034011,... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
8 0807301009 POLYGON ((2.073513537376484 41.35354297793097,... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
9 0807301010 POLYGON ((2.076351447228844 41.35300580311168,... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
10 0807301011 POLYGON ((2.075231238184402 41.3502418834029, ... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
11 0807301012 POLYGON ((2.078138395536048 41.34948543969318,... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
12 0807301013 POLYGON ((2.070673220012849 41.35183742555718,... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
13 0807301014 POLYGON ((2.068555991335256 41.3545286687766, ... 08 Cornell de Llobregat 08073 Catalua 09 0807301 Barcelona
14 0807302001 POLYGON ((2.093625220364088 41.3586287235924, ... 08 Cornell de Llobregat 08073 Catalua 09 0807302 Barcelona
15 0807302002 POLYGON ((2.098414563671479 41.35412837797859,... 08 Cornell de Llobregat 08073 Catalua 09 0807302 Barcelona
16 0807303001 POLYGON ((2.07611255018573 41.36475331743631, ... 08 Cornell de Llobregat 08073 Catalua 09 0807303 Barcelona
17 0807303002 POLYGON ((2.074202166513067 41.36662283360337,... 08 Cornell de Llobregat 08073 Catalua 09 0807303 Barcelona
18 0807303003 POLYGON ((2.073464007875069 41.36483626387965,... 08 Cornell de Llobregat 08073 Catalua 09 0807303 Barcelona
19 0807303004 POLYGON ((2.061162516025689 41.36492135114345,... 08 Cornell de Llobregat 08073 Catalua 09 0807303 Barcelona
20 0807303005 POLYGON ((2.070008926135653 41.36477759382425,... 08 Cornell de Llobregat 08073 Catalua 09 0807303 Barcelona
21 0807303006 POLYGON ((2.07603263954863 41.36467196132006, ... 08 Cornell de Llobregat 08073 Catalua 09 0807303 Barcelona
22 0807303007 POLYGON ((2.074968018258001 41.36358917264499,... 08 Cornell de Llobregat 08073 Catalua 09 0807303 Barcelona
23 0807303008 POLYGON ((2.063546649405958 41.35903638480863,... 08 Cornell de Llobregat 08073 Catalua 09 0807303 Barcelona
24 0807303009 POLYGON ((2.059556796436511 41.35907671405715,... 08 Cornell de Llobregat 08073 Catalua 09 0807303 Barcelona
25 0807304001 POLYGON ((2.074017914747701 41.35884374941005,... 08 Cornell de Llobregat 08073 Catalua 09 0807304 Barcelona
26 0807304002 POLYGON ((2.07694456943873 41.35708127848684, ... 08 Cornell de Llobregat 08073 Catalua 09 0807304 Barcelona
27 0807304003 POLYGON ((2.073510737054216 41.36047889484263,... 08 Cornell de Llobregat 08073 Catalua 09 0807304 Barcelona
28 0807304004 POLYGON ((2.080737635651198 41.35739498245629,... 08 Cornell de Llobregat 08073 Catalua 09 0807304 Barcelona
29 0807304005 POLYGON ((2.080048319263547 41.35832426126629,... 08 Cornell de Llobregat 08073 Catalua 09 0807304 Barcelona
... ... ... ... ... ... ... ... ... ...
295 0810106003 POLYGON ((2.107346478362054 41.35299296880945,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
296 0810106004 POLYGON ((2.10749779200804 41.34928961216207, ... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
297 0810106005 POLYGON ((2.109295564176914 41.35195179616392,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
298 0810106006 POLYGON ((2.108177365059811 41.34770648802841,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
299 0810106007 POLYGON ((2.109390191493859 41.34787372860216,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
300 0810106008 POLYGON ((2.116906950356888 41.3518333115553, ... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
301 0810106009 POLYGON ((2.1121606071758 41.35678368835044, 2... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
302 0810106010 POLYGON ((2.115694358677211 41.3550198169447, ... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
303 0810106011 POLYGON ((2.115942307489964 41.35669826603879,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
304 0810106012 POLYGON ((2.115731249011137 41.35532242585489,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
305 0810106013 POLYGON ((2.115576768962717 41.35405613070908,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
306 0810106014 POLYGON ((2.115341952095644 41.3521170374316, ... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
307 0810106015 POLYGON ((2.114575876857076 41.35080843961178,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
308 0810106016 POLYGON ((2.133252597556686 41.35985738233334,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
309 0810106017 POLYGON ((2.115526284594824 41.35364240699773,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
310 0810106018 POLYGON ((2.109157519956944 41.35219010358173,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
311 0810106019 POLYGON ((2.111164050408914 41.35010261037827,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
312 0810106020 POLYGON ((2.109694363132621 41.35353451084169,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
313 0810106021 POLYGON ((2.110529078703358 41.35377572756204,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
314 0810106022 POLYGON ((2.118425676973036 41.35454631841772,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
315 0810106023 POLYGON ((2.111416021000836 41.35621617853905,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
316 0810106024 POLYGON ((2.113550259973175 41.35606702378573,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
317 0810106025 POLYGON ((2.111410363308776 41.35275964605734,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
318 0810106026 POLYGON ((2.117658212025399 41.35182031837279,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
319 0810106027 POLYGON ((2.113536213566468 41.35301129383581,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
320 0810106028 POLYGON ((2.110999495684243 41.35050065082766,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
321 0810106029 POLYGON ((2.117633170576807 41.35397195269742,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
322 0810106030 POLYGON ((2.112889569395336 41.35435189716479,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
323 0810106031 POLYGON ((2.113107605274231 41.35047178057036,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona
324 0810106032 POLYGON ((2.115942307489964 41.35669826603879,... 08 Hospitalet de Llobregat, L' 08101 Catalua 09 0810106 Barcelona

325 rows × 9 columns


In [9]:
votos_2015_file = '/home/tono/code/Eleccions2017Cat/data/A20151_ME/Columnes_A20151_ME_ca_ES.csv'
data_info2015, votos2015 = parse_eleccions_2015_csv(votos_2015_file)

In [10]:
votos2015 = collapse_votes(votos2015)
data_info2015 = collapse_info_mesas(data_info2015)

In [11]:
votos2015


Out[11]:
CUSEC PSC PP C's PACMA JxSi CSQEP unio.cat CUP RECORTES0 pirata.cat ganemos
0 0800101001 175 84 201 14 249 106 18 70 4 0 0
1 0800101002 219 90 227 16 187 149 20 52 6 0 0
2 0800101003 74 28 114 4 158 52 7 31 5 0 0
3 0800101004 146 70 277 6 298 138 26 90 9 0 0
4 0800101005 247 100 246 10 174 143 18 68 13 0 0
5 0800101007 223 157 399 27 363 170 21 85 5 0 0
6 0800101008 191 90 307 5 256 180 21 57 9 0 0
7 0801401001 108 84 82 8 1048 83 54 159 1 0 0
8 0800301001 119 89 169 2 967 78 55 136 3 0 0
9 0800301002 97 164 273 10 686 84 52 100 3 0 0
10 0800301003 76 95 147 10 882 35 53 121 1 0 0
11 0800301004 90 133 263 8 614 67 47 112 1 0 0
12 0800501001 87 79 206 7 754 85 39 102 3 0 0
13 0800501002 55 52 94 1 696 45 33 81 2 0 0
14 0800501003 59 78 177 11 950 54 57 117 3 0 0
15 0800501004 34 34 81 1 368 44 18 46 2 0 0
16 0800501005 56 45 101 3 198 33 11 33 0 0 0
17 0800601001 114 106 123 8 733 74 45 148 4 0 0
18 0800601002 72 93 106 5 766 67 37 147 6 0 0
19 0800601003 62 51 59 5 401 32 25 51 0 0 0
20 0800601004 30 45 96 4 323 36 30 63 1 0 0
21 0800602001 87 68 81 2 534 67 22 85 0 0 0
22 0800602002 76 64 58 4 711 47 28 119 3 0 0
23 0800602003 82 90 109 2 587 40 24 84 1 0 0
24 0800602004 117 89 170 7 338 66 20 63 4 0 0
25 0800602005 140 81 107 4 365 64 17 43 0 0 0
26 0800701001 65 42 62 4 573 49 20 76 1 0 0
27 0800701002 130 88 165 6 1111 83 33 198 3 0 0
28 0800702001 67 79 95 5 874 48 45 141 4 0 0
29 0800702002 86 73 135 8 754 55 33 98 5 0 0
... ... ... ... ... ... ... ... ... ... ... ... ...
5018 4315501001 46 38 70 5 205 22 15 40 4 0 1
5019 4315501002 41 30 54 2 186 34 17 34 0 0 0
5020 4315501003 71 72 76 4 325 27 30 40 1 0 0
5021 4315501004 111 108 149 9 516 52 35 82 3 0 0
5022 4315501005 40 45 10 4 101 17 16 17 1 0 0
5023 4315501006 45 84 81 1 238 19 29 46 0 0 0
5024 4315501007 122 100 234 9 788 97 63 117 5 0 0
5025 4315502002 79 69 116 2 652 60 39 107 2 0 0
5026 4315502003 113 43 108 7 441 45 21 72 1 0 1
5027 4315502004 58 38 54 4 220 35 12 39 1 0 0
5028 4315502005 65 27 74 0 421 27 30 44 1 0 1
5029 4315503001 53 28 36 0 117 16 5 34 3 0 0
5030 4315503002 77 49 72 1 349 39 23 85 1 0 0
5031 4315503003 102 45 48 0 252 38 24 48 0 0 0
5032 4315503004 85 55 107 2 461 68 39 87 4 0 0
5033 4315504001 67 73 107 4 346 51 31 91 2 0 1
5034 4315504002 74 61 105 3 299 37 20 55 5 0 2
5035 4315504003 89 54 95 8 292 60 19 80 2 0 1
5036 4315504004 47 63 40 1 164 21 10 27 0 0 0
5037 4315504005 79 67 122 5 468 51 22 80 0 0 0
5038 4315504006 67 56 87 2 408 49 26 83 0 0 0
5039 4315504007 91 54 76 1 264 28 13 48 0 0 0
5040 4315504008 34 24 65 2 277 27 11 50 2 0 0
5041 4315504009 70 62 130 7 355 59 26 63 0 0 2
5042 4315601001 118 157 135 3 399 39 42 99 1 0 0
5043 4315601002 133 147 159 2 596 53 27 142 0 0 0
5044 4315602001 72 102 42 3 368 41 18 68 2 0 1
5045 4317501001 19 59 26 2 282 8 34 29 2 0 1
5046 4317701001 13 12 23 1 163 8 3 27 0 0 2
5047 4305201001 65 42 59 7 472 27 13 87 0 0 1

5048 rows × 12 columns


In [12]:
votos2015_trio_ll, codes_not_in_censo, codes_not_votos2015 =\
    left_filter_function(data_censo, votos2015, filter_code='CUSEC')

codes_not_in_censo, codes_not_votos2015


Out[12]:
({'0824502001',
  '4390301001',
  '0824502003',
  '0824502002',
  '0824502005',
  '0824502004',
  '0824502007',
  '0824502006',
  '0824502009',
  '0824502008',
  '1702901001',
  '0801908009',
  '0812402006',
  '4310101001',
  '0824503014',
  '1718601003',
  '1705801001',
  '4314802001',
  '4317101012',
  '1700101001',
  '0813601007',
  '0813601006',
  '0813601005',
  '0813601004',
  '0813601003',
  '0813601002',
  '0813601001',
  '4313001001',
  '0801905098',
  '0820501009',
  '2512003004',
  '0801905090',
  '0801905091',
  '0801905092',
  '0801905093',
  '0801905094',
  '0801905095',
  '0801905096',
  '0801905097',
  '2512003006',
  '0817701001',
  '0823101015',
  '0827902008',
  '0827902009',
  '2512003003',
  '0801507002',
  '0821701002',
  '0827902002',
  '0827902003',
  '0812105002',
  '0827902001',
  '0827902006',
  '0830704008',
  '0827902004',
  '0827902005',
  '0818701035',
  '4309601001',
  '0808903005',
  '0818701033',
  '0818701030',
  '0801907097',
  '0818701031',
  '0801907094',
  '1713201001',
  '0807801001',
  '0824506016',
  '0824506017',
  '0824506014',
  '0824506015',
  '0824506012',
  '0824506013',
  '0824506010',
  '0824506011',
  '0824504012',
  '0801910074',
  '0830704001',
  '0826001011',
  '0827905006',
  '0818704008',
  '2504003002',
  '0801907091',
  '4314809003',
  '0818704009',
  '0827905004',
  '2524201001',
  '1719301002',
  '2500301002',
  '2500301001',
  '1719301001',
  '2500301004',
  '0823001001',
  '0823001002',
  '0823001003',
  '0823001004',
  '0823001005',
  '0823001006',
  '1722101002',
  '1722101003',
  '1722101001',
  '1722101004',
  '0828101001',
  '0801907099',
  '0801909091',
  '0800601003',
  '0811302007',
  '0801909089',
  '0800501005',
  '0800501002',
  '0800501003',
  '0800501001',
  '0801909083',
  '0801909082',
  '0801909081',
  '0801909080',
  '0801909087',
  '0801909086',
  '0801909085',
  '0801909084',
  '0801910052',
  '0801910053',
  '0801910050',
  '0801910051',
  '0801910056',
  '0801910057',
  '0801910054',
  '0801910055',
  '0827905025',
  '0827905024',
  '0801910058',
  '0801910059',
  '0827905021',
  '0827905020',
  '0827905023',
  '0827905022',
  '0801903029',
  '0801903028',
  '0805401002',
  '4314804008',
  '0830101015',
  '0801903023',
  '0801903022',
  '0801903021',
  '0801903020',
  '0801903027',
  '0801903026',
  '0801903025',
  '0801903024',
  '0801904053',
  '0801904052',
  '0801904051',
  '0801904050',
  '4317501001',
  '0801904056',
  '0801904055',
  '0801904054',
  '4311701001',
  '2505501001',
  '4300701001',
  '0801509054',
  '0801509057',
  '0801509050',
  '4306201001',
  '0801509052',
  '0801509053',
  '1707903007',
  '0801509058',
  '0801509059',
  '1716901002',
  '1716901001',
  '1707501001',
  '0801906049',
  '4313802001',
  '2503501001',
  '4303501001',
  '1706501001',
  '0826601036',
  '0826301012',
  '0826301011',
  '0826601035',
  '0826601032',
  '0826601033',
  '0826601030',
  '0826601031',
  '2517401001',
  '0803501001',
  '0801001001',
  '0803501003',
  '0803501002',
  '0812503005',
  '0812503004',
  '0821701001',
  '0812503006',
  '0812503001',
  '0821701006',
  '0812503003',
  '0821701004',
  '0821701009',
  '0801903114',
  '0801903113',
  '0801903112',
  '0801903111',
  '0801903110',
  '2506701001',
  '4314805005',
  '4301402002',
  '0801905005',
  '4314805004',
  '1717401001',
  '4314805007',
  '1705501001',
  '4314805006',
  '0819501001',
  '1709504001',
  '1709504002',
  '0806301001',
  '1709504004',
  '0801907061',
  '0811202001',
  '0811202002',
  '0811202003',
  '0811202004',
  '0801509038',
  '1701901001',
  '2501902002',
  '1704402001',
  '1704402002',
  '0813101001',
  '0801902074',
  '0818705004',
  '0801910141',
  '0801907065',
  '0801907064',
  '1711401007',
  '0801907030',
  '0801907031',
  '0801907032',
  '0801907033',
  '0801907034',
  '0801907035',
  '0801907036',
  '0801907037',
  '0801907038',
  '0801907039',
  '0802202003',
  '0801509033',
  '2525001001',
  '0820501001',
  '0820501002',
  '0820501003',
  '0801906024',
  '0820501004',
  '0800602004',
  '0800602005',
  '0800602002',
  '0800602003',
  '0800602001',
  '0801902082',
  '0801902083',
  '0801902080',
  '0801902081',
  '0801902086',
  '0801902087',
  '0801902084',
  '0801902085',
  '0818702015',
  '0818702014',
  '0801902088',
  '0801902089',
  '0818702011',
  '0818702010',
  '0818702013',
  '0818702012',
  '0818706024',
  '0801908098',
  '0818706020',
  '0818706021',
  '0818706022',
  '0818706023',
  '4305401001',
  '0801508013',
  '0801508012',
  '0801508011',
  '0801907104',
  '0801907105',
  '0801907106',
  '0801907107',
  '0801907100',
  '0801907101',
  '0801907102',
  '0801907103',
  '0801907108',
  '0801907109',
  '2518501001',
  '0801906026',
  '2520702001',
  '2520702002',
  '0801906048',
  '0819404001',
  '0801901025',
  '0828701001',
  '0801909058',
  '2504701001',
  '0812701001',
  '0812701002',
  '0804601003',
  '0804601002',
  '0804601001',
  '0808401001',
  '4316104001',
  '0830501003',
  '0830501002',
  '0830501001',
  '2502301001',
  '2502301003',
  '2502301002',
  '4315401001',
  '4302001001',
  '4302001002',
  '0801909050',
  '1716201001',
  '0801909051',
  '1713501001',
  '4316103001',
  '0826201003',
  '0826201002',
  '0826201001',
  '2513701006',
  '2513701005',
  '2513701004',
  '2513701003',
  '2513701002',
  '2513701001',
  '1707906001',
  '0811305010',
  '4302201002',
  '0801909057',
  '0807201008',
  '0807201009',
  '0801902013',
  '0801905089',
  '0801905088',
  '0801905087',
  '0801905086',
  '0801905085',
  '0801905084',
  '0801905083',
  '0801905082',
  '0801905081',
  '0801905080',
  '0817401001',
  '4313701001',
  '0801503005',
  '4312101001',
  '0816101007',
  '0816101006',
  '0818201001',
  '0816101004',
  '0816101003',
  '0816101002',
  '0816101001',
  '0827902011',
  '0827902012',
  '0827902015',
  '0827902014',
  '0827902017',
  '0827902016',
  '0828401004',
  '1707902017',
  '0830102015',
  '2506901001',
  '0801905028',
  '0827906006',
  '0827906004',
  '0827906005',
  '0827906002',
  '0827906003',
  '0827906001',
  '0827906008',
  '0827906009',
  '4317301001',
  '0801902056',
  '0824506009',
  '0824506008',
  '0824506005',
  '0824506004',
  '0824506007',
  '0824506006',
  '0824506001',
  '0801905027',
  '0824506003',
  '0824506002',
  '4312902001',
  '0801908057',
  '4312902003',
  '4312902002',
  '0801908056',
  '0812106006',
  '0801905021',
  '4314806001',
  '1719901004',
  '0825201006',
  '0801905020',
  '0801902114',
  '4306601001',
  '0825201007',
  '2512005012',
  '0801902017',
  '0810701010',
  '0801908052',
  '4315502005',
  '0801908051',
  '0801908050',
  '0809201001',
  '0815902006',
  '0804901001',
  '1702303004',
  '1710501001',
  '1712801001',
  '0801904045',
  '2512007001',
  '1701001001',
  '2512007003',
  '2512007002',
  '2512007005',
  '2512007004',
  '2512007007',
  '2512007006',
  '0801910041',
  '0801910040',
  '0801910043',
  '0801910042',
  '0801910045',
  '0801910044',
  '0801910047',
  '0801910046',
  '0801910049',
  '0801910048',
  '0801908058',
  '0830704009',
  '4315602001',
  '0812104005',
  '0801903058',
  '0801903059',
  '0801903056',
  '0801903057',
  '0801903054',
  '0801903055',
  '0801903052',
  '0801903053',
  '0801903050',
  '0801903051',
  '0801904026',
  '0801904027',
  '0801509049',
  '0801904025',
  '0801904022',
  '0801904023',
  '0801904020',
  '0801904021',
  '0801509043',
  '0801509042',
  '0801509047',
  '0818301003',
  '0801509045',
  '0801509044',
  '0818703016',
  '0818703017',
  '1702801001',
  '0818703015',
  '0818703012',
  '0818703013',
  '0818703010',
  '0818703011',
  '0818707001',
  '0818707003',
  '0818707002',
  '0818707005',
  '0818707004',
  '1719401001',
  '0818703019',
  '0825201018',
  '1704801001',
  '1704801003',
  '1704801002',
  '1704801005',
  '1704801004',
  '0801504004',
  '0801504005',
  '0801504006',
  '0801504007',
  '0801504001',
  '0801504002',
  '0801504003',
  '1715401001',
  '0801504008',
  '0801504009',
  '0801902071',
  '0814001002',
  '0814001003',
  '0829101004',
  '0800701001',
  '0800701002',
  '4305402001',
  '1710001001',
  '2501701001',
  '0829101001',
  '0801903006',
  '2501301001',
  '1713701001',
  '4313901001',
  '0829101003',
  '0829101002',
  '0811303001',
  '1704601001',
  '4314301001',
  '2516101001',
  '2511501001',
  '0830801001',
  '0801910024',
  '0804602002',
  '0804602003',
  '0804602001',
  '2511001001',
  '0804602004',
  '2511001003',
  '0801907027',
  '0801907026',
  '0801907025',
  '0801907024',
  '0801907023',
  '0801907022',
  '0801907021',
  '0801907020',
  '0801910020',
  '0801907029',
  '0801907028',
  '1701501003',
  '1701501002',
  '1701501001',
  '1701501005',
  '1701501004',
  '0816902006',
  '0816902007',
  '0816902004',
  '0816902005',
  '0816902002',
  '0816902003',
  '0830702006',
  '0816902001',
  '1715202005',
  '0821402002',
  '0821402001',
  '0819801004',
  '0819801003',
  '0819801002',
  '0819801001',
  '0801902091',
  '0801902090',
  '0801902093',
  '0801902092',
  '0801902095',
  '0801902094',
  '0801902097',
  '0801902096',
  '0801902099',
  '0801902098',
  '0807201007',
  '0801907119',
  '0801907118',
  '0827601001',
  '0801907113',
  '0803502001',
  '0803502002',
  '0801907110',
  '0801907117',
  '0801907116',
  '0801907115',
  '0801907114',
  '0808602001',
  '0822501001',
  '0818001010',
  '1703001001',
  '0806101001',
  '2520501001',
  '4314401001',
  '2500301003',
  '0801905004',
  '0820503002',
  '2525201001',
  '1719301003',
  '4314804015',
  '2518201001',
  '0802204001',
  '0801502011',
  '0814102001',
  '0820503003',
  '1712001001',
  '0801909076',
  '2507501001',
  '0824501008',
  '0824501009',
  '0801909077',
  '0824501004',
  '0824501005',
  '0824501006',
  '0824501007',
  '0822001001',
  '0824501001',
  '0824501002',
  '0824501003',
  '0815601005',
  '0815601004',
  '0815601007',
  '0815601006',
  '0815601001',
  '0815601003',
  '0815601002',
  '0815601008',
  '4300601001',
  '0818402003',
  '0801101001',
  '2505601001',
  '0801909070',
  '0801906088',
  '0801906086',
  '0801906087',
  '0801906084',
  '0801906085',
  '0801906082',
  '0801906083',
  '0801906080',
  '0801906081',
  '0821401002',
  '0821401003',
  '0821401001',
  '0821401004',
  '0801905072',
  '0801905073',
  '0801905070',
  '0801905071',
  '0801905076',
  '0801905077',
  '0801905074',
  '0801905075',
  '0827905003',
  '0801905078',
  '0801905079',
  '0807201011',
  '0807201010',
  '0828501001',
  '0828501002',
  '0815801002',
  '0828501004',
  '1702303002',
  '0809602007',
  '0809602006',
  '0809602005',
  '0809602004',
  '0809602003',
  '0809602002',
  '0809602001',
  '0829901001',
  '0801902153',
  '0827905002',
  '0827301001',
  '0827301003',
  '0827301002',
  '1706602001',
  '2502101001',
  '0818801001',
  '0819701003',
  '0803503003',
  '1706602003',
  '4316106003',
  '1720001001',
  '0803503002',
  '0801901014',
  '0827906016',
  '0827906011',
  '0827905001',
  '0827906013',
  '0801901015',
  '0827906018',
  '1718301001',
  '4306001002',
  '1704701004',
  '0805602006',
  '0805602005',
  '1703801001',
  '0805602004',
  '1707903003',
  '1713901001',
  '0801502003',
  '0801906050',
  '0805101013',
  '0829803007',
  '0805603002',
  '0801906055',
  '4310901002',
  '0800501004',
  '4306901001',
  '0801901019',
  '0826601010',
  '0801909088',
  '0803201001',
  '0826601011',
  '1707904002',
  '0811702001',
  '4316201002',
  '2515301001',
  '0826601012',
  '1710601001',
  '2512003005',
  '1717701001',
  '2512003007',
  '0801504010',
  '2512003001',
  '0825701001',
  '0823501003',
  '0823501002',
  '0823501001',
  '1707904001',
  '0801502001',
  '2512003008',
  '0801906021',
  '0826601015',
  '4314809001',
  '0810202001',
  '0801910076',
  '0801910077',
  '0801910070',
  '0801910071',
  '0801910072',
  '0801910073',
  '4314809009',
  '4314809008',
  '0826601017',
  '0801910078',
  '0801910079',
  '0827905009',
  '0827905008',
  '2519301001',
  '4314806005',
  '0810202002',
  '0801903049',
  '0801903048',
  '0801903045',
  '0801903044',
  '0801903047',
  '0801903046',
  '0801903041',
  '0801903040',
  '0801903043',
  '0801903042',
  '0801904035',
  '0801904034',
  '0801904037',
  '0801904036',
  '0801904031',
  '0801904030',
  '4314805003',
  '4314805002',
  '0801509036',
  '0801509037',
  '0801509034',
  '0801509035',
  '0801904039',
  '0801904038',
  '0801509030',
  '0801509031',
  '0818703005',
  '0818703004',
  '0818703007',
  '0818703006',
  '0818703001',
  '0818703003',
  '0818703002',
  '0828101003',
  '0822101002',
  '0818703009',
  '0818703008',
  '0801908087',
  '4314101001',
  '1716001001',
  '1716001002',
  '0811001006',
  '0811001005',
  '0811001004',
  '0811001003',
  '0811001002',
  '0811001001',
  '0827905028',
  '0810701006',
  '1720701001',
  '0816903012',
  '0816903013',
  '0816903010',
  '0816903011',
  '0815901004',
  '0815901001',
  '0815901002',
  '0815901003',
  '0801908116',
  '0801908114',
  '0801908115',
  '0801908112',
  '0801908113',
  '0801908110',
  '0801908111',
  '0827905026',
  '1702101001',
  '1714601001',
  '1714601002',
  '2512301001',
  '4390701001',
  '0819601012',
  '0819601013',
  '0819601010',
  '0819601011',
  '0819601014',
  '1700501001',
  '0811203004',
  '0811203003',
  '0811203002',
  '0811203001',
  '0825401001',
  '0801902147',
  '0801902146',
  '2515801001',
  '0801908022',
  '0801908023',
  '0801908020',
  '0801908021',
  '0801908026',
  '0801908027',
  '0801908024',
  '0801908025',
  '4316106001',
  '0801908028',
  '0801908029',
  '4316106005',
  '4316106004',
  '4316106006',
  '0826601018',
  '0826601019',
  '4304801001',
  '4314804007',
  '0801504013',
  '0801504012',
  '0801504011',
  '4317001001',
  '0826601014',
  '0801504016',
  '0801504015',
  '0801504014',
  '0818404012',
  '0818404013',
  '0818404010',
  '0818404011',
  '0818404016',
  '0818404014',
  '0818404015',
  '1720701002',
  '4306701001',
  '0818404018',
  '0818404019',
  '4314804003',
  '1710201001',
  '0815001001',
  '0819001001',
  '0810602001',
  '4314804001',
  '2512901001',
  '0802301004',
  '0802301005',
  '0802301002',
  '0802301003',
  '0810602003',
  '0802301001',
  '1710301001',
  '0810602002',
  '0820006003',
  '0805601002',
  '0805601003',
  '0805601001',
  '0805601006',
  '0805601007',
  '0805601004',
  '0805601005',
  '0828001001',
  '0820006001',
  '2508101001',
  '0809603010',
  '4312303004',
  '0800902002',
  '0800902001',
  '4312303007',
  '4311301001',
  '4312303001',
  '4312303003',
  '4309301002',
  '4314801001',
  '4309301001',
  '4312303008',
  '4312303009',
  '0818702017',
  '0801902138',
  '4313401001',
  '0801902132',
  '0801902133',
  '0801902130',
  '0801902131',
  '0801902136',
  '0801902137',
  '0801902134',
  '0801902135',
  '4300201001',
  '2520901001',
  '2512005007',
  '2501301002',
  '1701301003',
  '1701301002',
  '0820504003',
  '0820504002',
  '0820504001',
  '0809001001',
  '0824501013',
  '0824501012',
  '0824501011',
  '0824501010',
  '0824501017',
  '0824501016',
  '0824501015',
  '0824501014',
  '0824501019',
  '0824501018',
  '0805301001',
  '0805301002',
  '1720901001',
  '0801907048',
  '0810901001',
  '0827401001',
  '0827401002',
  '0827401004',
  '0827401005',
  '2514101001',
  '1715201005',
  '1715201004',
  '1719801001',
  '1715201006',
  '1715201001',
  '0810701004',
  '1715201003',
  '1715201002',
  '0827905012',
  '0801908093',
  '0801905061',
  '0801901033',
  '0801905063',
  '0801905062',
  '0801901036',
  '0801905064',
  '0801905067',
  '0801905066',
  '0801905069',
  '0801905068',
  '0801901038',
  '0801901039',
  '4304701002',
  '0801906047',
  '1718001005',
  '1714704001',
  '0801903105',
  '0812106005',
  '1703101001',
  '0826801001',
  '0801509004',
  '0826801002',
  '0800401001',
  '0801801001',
  '0801801002',
  '0801801003',
  '0802601001',
  '0809601010',
  '0803001002',
  '0824505008',
  '0824505009',
  '2510001001',
  '4312302015',
  '0824505002',
  '0824505003',
  '4312302010',
  '0824505005',
  '0824505006',
  '0824505007',
  '4301201001',
  '0821702003',
  '4301201003',
  '4301201002',
  '0821702004',
  ...},
 {'0810102003',
  '0810102006',
  '0810102015',
  '0810102018',
  '0810102019',
  '0810102022',
  '0810102025',
  '0810102027',
  '0810102030',
  '0810102035',
  '0810102041',
  '0810102044',
  '0810104008',
  '0810104013',
  '0810104015',
  '0810104017',
  '0810104024',
  '0810104028',
  '0810104029',
  '0810104034',
  '0810104038',
  '0810104039',
  '0810104042',
  '0810105009',
  '0810105012',
  '0810105015',
  '0810105016',
  '0810105019',
  '0810105022',
  '0810105027',
  '0810105036',
  '0810106003',
  '0810106004',
  '0810106020',
  '0810106028',
  '0810106029'})

In [13]:
datainfo2015_trio_ll, codes_not_in_censo, codes_not_datainfo2015 =\
    left_filter_function(data_censo, data_info2015, filter_code='CUSEC')
codes_not_in_censo, codes_not_datainfo2015


/usr/local/lib/python2.7/dist-packages/pandas/indexes/base.py:2286: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  indexer = self._engine.get_indexer(target._values)
/usr/local/lib/python2.7/dist-packages/pandas/indexes/base.py:1396: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  return key in self._engine
Out[13]:
({'0824502001',
  '4390301001',
  '0824502003',
  '0824502002',
  '0824502005',
  '0824502004',
  '0824502007',
  '0824502006',
  '0824502009',
  '0824502008',
  '1702901001',
  '0801908009',
  '0812402006',
  '4310101001',
  '0824503014',
  '1718601003',
  '1705801001',
  '4314802001',
  '4317101012',
  '1700101001',
  '0813601007',
  '0813601006',
  '0813601005',
  '0813601004',
  '0813601003',
  '0813601002',
  '0813601001',
  '4313001001',
  '0801905098',
  '0820501009',
  '2512003004',
  '0801905090',
  '0801905091',
  '0801905092',
  '0801905093',
  '0801905094',
  '0801905095',
  '0801905096',
  '0801905097',
  '2512003006',
  '0817701001',
  '0823101015',
  '0827902008',
  '0827902009',
  '2512003003',
  '0801507002',
  '0821701002',
  '0827902002',
  '0827902003',
  '0812105002',
  '0827902001',
  '0827902006',
  '0830704008',
  '0827902004',
  '0827902005',
  '0818701035',
  '4309601001',
  '0808903005',
  '0818701033',
  '0818701030',
  '0801907097',
  '0818701031',
  '0801907094',
  '1713201001',
  '0807801001',
  '0824506016',
  '0824506017',
  '0824506014',
  '0824506015',
  '0824506012',
  '0824506013',
  '0824506010',
  '0824506011',
  '0824504012',
  '0801910074',
  '0830704001',
  '0826001011',
  '0827905006',
  '0818704008',
  '2504003002',
  '0801907091',
  '4314809003',
  '0818704009',
  '0827905004',
  '2524201001',
  '1719301002',
  '2500301002',
  '2500301001',
  '1719301001',
  '2500301004',
  '0823001001',
  '0823001002',
  '0823001003',
  '0823001004',
  '0823001005',
  '0823001006',
  '1722101002',
  '1722101003',
  '1722101001',
  '1722101004',
  '0828101001',
  '0801907099',
  '0801909091',
  '0800601003',
  '0811302007',
  '0801909089',
  '0800501005',
  '0800501002',
  '0800501003',
  '0800501001',
  '0801909083',
  '0801909082',
  '0801909081',
  '0801909080',
  '0801909087',
  '0801909086',
  '0801909085',
  '0801909084',
  '0801910052',
  '0801910053',
  '0801910050',
  '0801910051',
  '0801910056',
  '0801910057',
  '0801910054',
  '0801910055',
  '0827905025',
  '0827905024',
  '0801910058',
  '0801910059',
  '0827905021',
  '0827905020',
  '0827905023',
  '0827905022',
  '0801903029',
  '0801903028',
  '0805401002',
  '4314804008',
  '0830101015',
  '0801903023',
  '0801903022',
  '0801903021',
  '0801903020',
  '0801903027',
  '0801903026',
  '0801903025',
  '0801903024',
  '0801904053',
  '0801904052',
  '0801904051',
  '0801904050',
  '4317501001',
  '0801904056',
  '0801904055',
  '0801904054',
  '4311701001',
  '2505501001',
  '4300701001',
  '0801509054',
  '0801509057',
  '0801509050',
  '4306201001',
  '0801509052',
  '0801509053',
  '1707903007',
  '0801509058',
  '0801509059',
  '1716901002',
  '1716901001',
  '1707501001',
  '0801906049',
  '4313802001',
  '2503501001',
  '4303501001',
  '1706501001',
  '0826601036',
  '0826301012',
  '0826301011',
  '0826601035',
  '0826601032',
  '0826601033',
  '0826601030',
  '0826601031',
  '2517401001',
  '0803501001',
  '0801001001',
  '0803501003',
  '0803501002',
  '0812503005',
  '0812503004',
  '0821701001',
  '0812503006',
  '0812503001',
  '0821701006',
  '0812503003',
  '0821701004',
  '0821701009',
  '0801903114',
  '0801903113',
  '0801903112',
  '0801903111',
  '0801903110',
  '2506701001',
  '4314805005',
  '4301402002',
  '0801905005',
  '4314805004',
  '1717401001',
  '4314805007',
  '1705501001',
  '4314805006',
  '0819501001',
  '1709504001',
  '1709504002',
  '0806301001',
  '1709504004',
  '0801907061',
  '0811202001',
  '0811202002',
  '0811202003',
  '0811202004',
  '0801509038',
  '1701901001',
  '2501902002',
  '1704402001',
  '1704402002',
  '0813101001',
  '0801902074',
  '0818705004',
  '0801910141',
  '0801907065',
  '0801907064',
  '1711401007',
  '0801907030',
  '0801907031',
  '0801907032',
  '0801907033',
  '0801907034',
  '0801907035',
  '0801907036',
  '0801907037',
  '0801907038',
  '0801907039',
  '0802202003',
  '0801509033',
  '2525001001',
  '0820501001',
  '0820501002',
  '0820501003',
  '0801906024',
  '0820501004',
  '0800602004',
  '0800602005',
  '0800602002',
  '0800602003',
  '0800602001',
  '0801902082',
  '0801902083',
  '0801902080',
  '0801902081',
  '0801902086',
  '0801902087',
  '0801902084',
  '0801902085',
  '0818702015',
  '0818702014',
  '0801902088',
  '0801902089',
  '0818702011',
  '0818702010',
  '0818702013',
  '0818702012',
  '0818706024',
  '0801908098',
  '0818706020',
  '0818706021',
  '0818706022',
  '0818706023',
  '4305401001',
  '0801508013',
  '0801508012',
  '0801508011',
  '0801907104',
  '0801907105',
  '0801907106',
  '0801907107',
  '0801907100',
  '0801907101',
  '0801907102',
  '0801907103',
  '0801907108',
  '0801907109',
  '2518501001',
  '0801906026',
  '2520702001',
  '2520702002',
  '0801906048',
  '0819404001',
  '0801901025',
  '0828701001',
  '0801909058',
  '2504701001',
  '0812701001',
  '0812701002',
  '0804601003',
  '0804601002',
  '0804601001',
  '0808401001',
  '4316104001',
  '0830501003',
  '0830501002',
  '0830501001',
  '2502301001',
  '2502301003',
  '2502301002',
  '4315401001',
  '4302001001',
  '4302001002',
  '0801909050',
  '1716201001',
  '0801909051',
  '1713501001',
  '4316103001',
  '0826201003',
  '0826201002',
  '0826201001',
  '2513701006',
  '2513701005',
  '2513701004',
  '2513701003',
  '2513701002',
  '2513701001',
  '1707906001',
  '0811305010',
  '4302201002',
  '0801909057',
  '0807201008',
  '0807201009',
  '0801902013',
  '0801905089',
  '0801905088',
  '0801905087',
  '0801905086',
  '0801905085',
  '0801905084',
  '0801905083',
  '0801905082',
  '0801905081',
  '0801905080',
  '0817401001',
  '4313701001',
  '0801503005',
  '4312101001',
  '0816101007',
  '0816101006',
  '0818201001',
  '0816101004',
  '0816101003',
  '0816101002',
  '0816101001',
  '0827902011',
  '0827902012',
  '0827902015',
  '0827902014',
  '0827902017',
  '0827902016',
  '0828401004',
  '1707902017',
  '0830102015',
  '2506901001',
  '0801905028',
  '0827906006',
  '0827906004',
  '0827906005',
  '0827906002',
  '0827906003',
  '0827906001',
  '0827906008',
  '0827906009',
  '4317301001',
  '0801902056',
  '0824506009',
  '0824506008',
  '0824506005',
  '0824506004',
  '0824506007',
  '0824506006',
  '0824506001',
  '0801905027',
  '0824506003',
  '0824506002',
  '4312902001',
  '0801908057',
  '4312902003',
  '4312902002',
  '0801908056',
  '0812106006',
  '0801905021',
  '4314806001',
  '1719901004',
  '0825201006',
  '0801905020',
  '0801902114',
  '4306601001',
  '0825201007',
  '2512005012',
  '0801902017',
  '0810701010',
  '0801908052',
  '4315502005',
  '0801908051',
  '0801908050',
  '0809201001',
  '0815902006',
  '0804901001',
  '1702303004',
  '1710501001',
  '1712801001',
  '0801904045',
  '2512007001',
  '1701001001',
  '2512007003',
  '2512007002',
  '2512007005',
  '2512007004',
  '2512007007',
  '2512007006',
  '0801910041',
  '0801910040',
  '0801910043',
  '0801910042',
  '0801910045',
  '0801910044',
  '0801910047',
  '0801910046',
  '0801910049',
  '0801910048',
  '0801908058',
  '0830704009',
  '4315602001',
  '0812104005',
  '0801903058',
  '0801903059',
  '0801903056',
  '0801903057',
  '0801903054',
  '0801903055',
  '0801903052',
  '0801903053',
  '0801903050',
  '0801903051',
  '0801904026',
  '0801904027',
  '0801509049',
  '0801904025',
  '0801904022',
  '0801904023',
  '0801904020',
  '0801904021',
  '0801509043',
  '0801509042',
  '0801509047',
  '0818301003',
  '0801509045',
  '0801509044',
  '0818703016',
  '0818703017',
  '1702801001',
  '0818703015',
  '0818703012',
  '0818703013',
  '0818703010',
  '0818703011',
  '0818707001',
  '0818707003',
  '0818707002',
  '0818707005',
  '0818707004',
  '1719401001',
  '0818703019',
  '0825201018',
  '1704801001',
  '1704801003',
  '1704801002',
  '1704801005',
  '1704801004',
  '0801504004',
  '0801504005',
  '0801504006',
  '0801504007',
  '0801504001',
  '0801504002',
  '0801504003',
  '1715401001',
  '0801504008',
  '0801504009',
  '0801902071',
  '0814001002',
  '0814001003',
  '0829101004',
  '0800701001',
  '0800701002',
  '4305402001',
  '1710001001',
  '2501701001',
  '0829101001',
  '0801903006',
  '2501301001',
  '1713701001',
  '4313901001',
  '0829101003',
  '0829101002',
  '0811303001',
  '1704601001',
  '4314301001',
  '2516101001',
  '2511501001',
  '0830801001',
  '0801910024',
  '0804602002',
  '0804602003',
  '0804602001',
  '2511001001',
  '0804602004',
  '2511001003',
  '0801907027',
  '0801907026',
  '0801907025',
  '0801907024',
  '0801907023',
  '0801907022',
  '0801907021',
  '0801907020',
  '0801910020',
  '0801907029',
  '0801907028',
  '1701501003',
  '1701501002',
  '1701501001',
  '1701501005',
  '1701501004',
  '0816902006',
  '0816902007',
  '0816902004',
  '0816902005',
  '0816902002',
  '0816902003',
  '0830702006',
  '0816902001',
  '1715202005',
  '0821402002',
  '0821402001',
  '0819801004',
  '0819801003',
  '0819801002',
  '0819801001',
  '0801902091',
  '0801902090',
  '0801902093',
  '0801902092',
  '0801902095',
  '0801902094',
  '0801902097',
  '0801902096',
  '0801902099',
  '0801902098',
  '0807201007',
  '0801907119',
  '0801907118',
  '0827601001',
  '0801907113',
  '0803502001',
  '0803502002',
  '0801907110',
  '0801907117',
  '0801907116',
  '0801907115',
  '0801907114',
  '0808602001',
  '0822501001',
  '0818001010',
  '1703001001',
  '0806101001',
  '2520501001',
  '4314401001',
  '2500301003',
  '0801905004',
  '0820503002',
  '2525201001',
  '1719301003',
  '4314804015',
  '2518201001',
  '0802204001',
  '0801502011',
  '0814102001',
  '0820503003',
  '1712001001',
  '0801909076',
  '2507501001',
  '0824501008',
  '0824501009',
  '0801909077',
  '0824501004',
  '0824501005',
  '0824501006',
  '0824501007',
  '0822001001',
  '0824501001',
  '0824501002',
  '0824501003',
  '0815601005',
  '0815601004',
  '0815601007',
  '0815601006',
  '0815601001',
  '0815601003',
  '0815601002',
  '0815601008',
  '4300601001',
  '0818402003',
  '0801101001',
  '2505601001',
  '0801909070',
  '0801906088',
  '0801906086',
  '0801906087',
  '0801906084',
  '0801906085',
  '0801906082',
  '0801906083',
  '0801906080',
  '0801906081',
  '0821401002',
  '0821401003',
  '0821401001',
  '0821401004',
  '0801905072',
  '0801905073',
  '0801905070',
  '0801905071',
  '0801905076',
  '0801905077',
  '0801905074',
  '0801905075',
  '0827905003',
  '0801905078',
  '0801905079',
  '0807201011',
  '0807201010',
  '0828501001',
  '0828501002',
  '0815801002',
  '0828501004',
  '1702303002',
  '0809602007',
  '0809602006',
  '0809602005',
  '0809602004',
  '0809602003',
  '0809602002',
  '0809602001',
  '0829901001',
  '0801902153',
  '0827905002',
  '0827301001',
  '0827301003',
  '0827301002',
  '1706602001',
  '2502101001',
  '0818801001',
  '0819701003',
  '0803503003',
  '1706602003',
  '4316106003',
  '1720001001',
  '0803503002',
  '0801901014',
  '0827906016',
  '0827906011',
  '0827905001',
  '0827906013',
  '0801901015',
  '0827906018',
  '1718301001',
  '4306001002',
  '1704701004',
  '0805602006',
  '0805602005',
  '1703801001',
  '0805602004',
  '1707903003',
  '1713901001',
  '0801502003',
  '0801906050',
  '0805101013',
  '0829803007',
  '0805603002',
  '0801906055',
  '4310901002',
  '0800501004',
  '4306901001',
  '0801901019',
  '0826601010',
  '0801909088',
  '0803201001',
  '0826601011',
  '1707904002',
  '0811702001',
  '4316201002',
  '2515301001',
  '0826601012',
  '1710601001',
  '2512003005',
  '1717701001',
  '2512003007',
  '0801504010',
  '2512003001',
  '0825701001',
  '0823501003',
  '0823501002',
  '0823501001',
  '1707904001',
  '0801502001',
  '2512003008',
  '0801906021',
  '0826601015',
  '4314809001',
  '0810202001',
  '0801910076',
  '0801910077',
  '0801910070',
  '0801910071',
  '0801910072',
  '0801910073',
  '4314809009',
  '4314809008',
  '0826601017',
  '0801910078',
  '0801910079',
  '0827905009',
  '0827905008',
  '2519301001',
  '4314806005',
  '0810202002',
  '0801903049',
  '0801903048',
  '0801903045',
  '0801903044',
  '0801903047',
  '0801903046',
  '0801903041',
  '0801903040',
  '0801903043',
  '0801903042',
  '0801904035',
  '0801904034',
  '0801904037',
  '0801904036',
  '0801904031',
  '0801904030',
  '4314805003',
  '4314805002',
  '0801509036',
  '0801509037',
  '0801509034',
  '0801509035',
  '0801904039',
  '0801904038',
  '0801509030',
  '0801509031',
  '0818703005',
  '0818703004',
  '0818703007',
  '0818703006',
  '0818703001',
  '0818703003',
  '0818703002',
  '0828101003',
  '0822101002',
  '0818703009',
  '0818703008',
  '0801908087',
  '4314101001',
  '1716001001',
  '1716001002',
  '0811001006',
  '0811001005',
  '0811001004',
  '0811001003',
  '0811001002',
  '0811001001',
  '0827905028',
  '0810701006',
  '1720701001',
  '0816903012',
  '0816903013',
  '0816903010',
  '0816903011',
  '0815901004',
  '0815901001',
  '0815901002',
  '0815901003',
  '0801908116',
  '0801908114',
  '0801908115',
  '0801908112',
  '0801908113',
  '0801908110',
  '0801908111',
  '0827905026',
  '1702101001',
  '1714601001',
  '1714601002',
  '2512301001',
  '4390701001',
  '0819601012',
  '0819601013',
  '0819601010',
  '0819601011',
  '0819601014',
  '1700501001',
  '0811203004',
  '0811203003',
  '0811203002',
  '0811203001',
  '0825401001',
  '0801902147',
  '0801902146',
  '2515801001',
  '0801908022',
  '0801908023',
  '0801908020',
  '0801908021',
  '0801908026',
  '0801908027',
  '0801908024',
  '0801908025',
  '4316106001',
  '0801908028',
  '0801908029',
  '4316106005',
  '4316106004',
  '4316106006',
  '0826601018',
  '0826601019',
  '4304801001',
  '4314804007',
  '0801504013',
  '0801504012',
  '0801504011',
  '4317001001',
  '0826601014',
  '0801504016',
  '0801504015',
  '0801504014',
  '0818404012',
  '0818404013',
  '0818404010',
  '0818404011',
  '0818404016',
  '0818404014',
  '0818404015',
  '1720701002',
  '4306701001',
  '0818404018',
  '0818404019',
  '4314804003',
  '1710201001',
  '0815001001',
  '0819001001',
  '0810602001',
  '4314804001',
  '2512901001',
  '0802301004',
  '0802301005',
  '0802301002',
  '0802301003',
  '0810602003',
  '0802301001',
  '1710301001',
  '0810602002',
  '0820006003',
  '0805601002',
  '0805601003',
  '0805601001',
  '0805601006',
  '0805601007',
  '0805601004',
  '0805601005',
  '0828001001',
  '0820006001',
  '2508101001',
  '0809603010',
  '4312303004',
  '0800902002',
  '0800902001',
  '4312303007',
  '4311301001',
  '4312303001',
  '4312303003',
  '4309301002',
  '4314801001',
  '4309301001',
  '4312303008',
  '4312303009',
  '0818702017',
  '0801902138',
  '4313401001',
  '0801902132',
  '0801902133',
  '0801902130',
  '0801902131',
  '0801902136',
  '0801902137',
  '0801902134',
  '0801902135',
  '4300201001',
  '2520901001',
  '2512005007',
  '2501301002',
  '1701301003',
  '1701301002',
  '0820504003',
  '0820504002',
  '0820504001',
  '0809001001',
  '0824501013',
  '0824501012',
  '0824501011',
  '0824501010',
  '0824501017',
  '0824501016',
  '0824501015',
  '0824501014',
  '0824501019',
  '0824501018',
  '0805301001',
  '0805301002',
  '1720901001',
  '0801907048',
  '0810901001',
  '0827401001',
  '0827401002',
  '0827401004',
  '0827401005',
  '2514101001',
  '1715201005',
  '1715201004',
  '1719801001',
  '1715201006',
  '1715201001',
  '0810701004',
  '1715201003',
  '1715201002',
  '0827905012',
  '0801908093',
  '0801905061',
  '0801901033',
  '0801905063',
  '0801905062',
  '0801901036',
  '0801905064',
  '0801905067',
  '0801905066',
  '0801905069',
  '0801905068',
  '0801901038',
  '0801901039',
  '4304701002',
  '0801906047',
  '1718001005',
  '1714704001',
  '0801903105',
  '0812106005',
  '1703101001',
  '0826801001',
  '0801509004',
  '0826801002',
  '0800401001',
  '0801801001',
  '0801801002',
  '0801801003',
  '0802601001',
  '0809601010',
  '0803001002',
  '0824505008',
  '0824505009',
  '2510001001',
  '4312302015',
  '0824505002',
  '0824505003',
  '4312302010',
  '0824505005',
  '0824505006',
  '0824505007',
  '4301201001',
  '0821702003',
  '4301201003',
  '4301201002',
  '0821702004',
  ...},
 {'0810102003',
  '0810102006',
  '0810102015',
  '0810102018',
  '0810102019',
  '0810102022',
  '0810102025',
  '0810102027',
  '0810102030',
  '0810102035',
  '0810102041',
  '0810102044',
  '0810104008',
  '0810104013',
  '0810104015',
  '0810104017',
  '0810104024',
  '0810104028',
  '0810104029',
  '0810104034',
  '0810104038',
  '0810104039',
  '0810104042',
  '0810105009',
  '0810105012',
  '0810105015',
  '0810105016',
  '0810105019',
  '0810105022',
  '0810105027',
  '0810105036',
  '0810106003',
  '0810106004',
  '0810106020',
  '0810106028',
  '0810106029'})

In [8]:
elections2015 = '/home/tono/code/Eleccions2017Cat/data/A20151_ME/Columnes_A20151_ME_ca_ES.csv'

converters = {}
data2015 = pd.read_csv(elections2015, sep=';', converters=converters)

columns = ['Codi Província', 'Nom Província', 'Codi Vegueria', 'Nom Vegueria',
           'Codi Comarca', 'Nom Comarca', 'Codi Municipi', 'Nom Municipi',
           'Districte', 'Secció', 'Mesa', 'Cens electoral',
           'Participació 13:00', 'Participació 18.00', 'Participació 20.00',
           'Abstenció', 'Vots nuls', 'Vots en blanc', 'Vots a candidatures',
           'Vots vàlids']
n_cols = len(columns)
cols_new = [str(c) for c in data2015.columns]
data2015.columns = cols_new


votos = data2015.columns[len(columns):][[2*i for i in range((len(data2015.columns)-len(columns))//2)]]
parties = ["PSC", "PP", "C's", "PACMA", "JxSi", "CSQEP", "unio.cat", "CUP", "RECORTES0", "pirata.cat", "ganemos"]
votos_data2015 = data2015[votos]
votos_data2015.columns = parties

#data2015[data2015.columns[:20]]

CUSEC =\
    [str(data2015.iloc[i, 6]).zfill(5)+str(data2015.iloc[i, 8]).zfill(2)+str(data2015.iloc[i, 9]).zfill(3)
     for i in range(len(data2015))]
CUSEC2015 = pd.DataFrame(pd.Series(CUSEC), columns=['CUSEC'])

votos2015 = pd.concat([CUSEC2015, votos_data2015], axis=1)

In [ ]:
for cusec in votos2015['CUSEC']:
    if cusec not in list(data_censo['CUSEC']):
        print(cusec)


0800101001
0800101002
0800101003
0800101004
0800101005
0800101007
0800101008
0801401001
0800301001
0800301002
0800301003
0800301004
0800501001
0800501002
0800501003
0800501004
0800501005
0800601001
0800601002
0800601003
0800601004
0800602001
0800602002
0800602003
0800602004
0800602005
0800701001
0800701002
0800702001
0800702002
0800901001
0800901002
0800901003
0800901004
0800901005
0800901006
0800902001
0800902002
0801301001
0801501001
0801501002
0801501003
0801501004
0801501005
0801501007
0801501008
0801502001
0801502010
0801502011
0801502012
0801502013
0801502015
0801502002
0801502003
0801502004
0801502005
0801502007
0801502008
0801502009
0801503001
0801503010
0801503011
0801503013
0801503003
0801503004
0801503005
0801503006
0801503007
0801503008
0801503009
0801504001
0801504010
0801504011
0801504012
0801504013
0801504014
0801504015
0801504016
0801504002
0801504003
0801504004
0801504005
0801504006
0801504007
0801504008
0801504009
0801505001
0801505002
0801505003
0801505004
0801505005
0801505006
0801506001
0801506002
0801506003
0801506004
0801506005
0801506006
0801507001
0801507010
0801507011
0801507012
0801507013
0801507014
0801507015
0801507017
0801507018
0801507002
0801507020
0801507021
0801507022
0801507023
0801507024
0801507028
0801507029
0801507003
0801507030
0801507031
0801507004
0801507005
0801507006
0801507007
0801507008
0801507009
0801508001
0801508011
0801508012
0801508013
0801508002
0801508003
0801508004
0801508005
0801508006
0801508007
0801508008
0801508009
0801509001
0801509010
0801509011
0801509012
0801509013
0801509014
0801509015
0801509016
0801509017
0801509018
0801509019
0801509002
0801509020
0801509021
0801509022
0801509023
0801509024
0801509025
0801509026
0801509027
0801509028
0801509003
0801509030
0801509031
0801509032
0801509033
0801509034
0801509035
0801509036
0801509037
0801509038
0801509004
0801509042
0801509043
0801509044
0801509045
0801509047
0801509049
0801509005
0801509050
0801509052
0801509053
0801509054
0801509057
0801509058
0801509059
0801509006
0801509008
0801509009
0890401001
0890401010
0890401011
0890401012
0890401002
0890401003
0890401004
0890401005
0890401006
0890401007
0890401008
0890401009
0825201001
0825201010
0825201011
0825201018
0825201019
0825201002
0825201020
0825201021
0825201022
0825201023
0825201024
0825201025
0825201026
0825201027
0825201028
0825201029
0825201003
0825201004
0825201005
0825201006
0825201007
0825201008
0825201009
0801901001
0801901010
0801901011
0801901012
0801901013
0801901014
0801901015
0801901016
0801901017
0801901018
0801901019
0801901002
0801901020
0801901021
0801901022
0801901023
0801901025
0801901026
0801901027
0801901028
0801901029
0801901003
0801901030
0801901031
0801901032
0801901033
0801901034
0801901035
0801901036
0801901037
0801901038
0801901039
0801901004
0801901040
0801901041
0801901042
0801901043
0801901044
0801901045
0801901046
0801901047
0801901048
0801901049
0801901005
0801901050
0801901051
0801901052
0801901053
0801901054
0801901055
0801901006
0801901007
0801901008
0801901009
0801910001
0801910010
0801910100
0801910101
0801910102
0801910103
0801910104
0801910105
0801910106
0801910107
0801910108
0801910109
0801910011
0801910110
0801910111
0801910112
0801910113
0801910114
0801910115
0801910116
0801910117
0801910118
0801910119
0801910012
0801910120
0801910121
0801910122
0801910123
0801910124
0801910125
0801910126
0801910127
0801910128
0801910129
0801910013
0801910130
0801910131
0801910132
0801910133
0801910134
0801910135
0801910136
0801910137
0801910138
0801910139
0801910014
0801910140
0801910141
0801910142
0801910143
0801910015
0801910016
0801910017
0801910018
0801910019
0801910002
0801910020
0801910021
0801910022
0801910023
0801910234
0801910235
0801910236
0801910237
0801910024
0801910025
0801910026
0801910027
0801910028
0801910029
0801910003
0801910030
0801910031
0801910032
0801910033
0801910034
0801910035
0801910036
0801910037
0801910038
0801910039
0801910004
0801910040
0801910041
0801910042
0801910043
0801910044
0801910045
0801910046
0801910047
0801910048
0801910049
0801910005
0801910050
0801910051
0801910052
0801910053
0801910054
0801910055
0801910056
0801910057
0801910058
0801910059
0801910006
0801910060
0801910061
0801910062
0801910063
0801910064
0801910065
0801910066
0801910067
0801910068
0801910069
0801910007
0801910070
0801910071
0801910072
0801910073
0801910074
0801910075
0801910076
0801910077
0801910078
0801910079
0801910008
0801910080
0801910081
0801910082
0801910083
0801910084
0801910085
0801910086
0801910087
0801910088
0801910089
0801910009
0801910090
0801910091
0801910092
0801910093
0801910094
0801910095
0801910096
0801910097
0801910098
0801910099
0801902001
0801902010
0801902100
0801902101
0801902102
0801902103
0801902104
0801902105
0801902106
0801902107
0801902108
0801902109
0801902011
0801902110
0801902111
0801902112
0801902113
0801902114
0801902115
0801902116
0801902117
0801902118
0801902119
0801902012
0801902120
0801902121
0801902122
0801902123
0801902124
0801902125
0801902126
0801902127
0801902128
0801902129
0801902013
0801902130
0801902131
0801902132
0801902133
0801902134
0801902135
0801902136
0801902137
0801902138
0801902139
0801902014
0801902140
0801902141
0801902142
0801902143
0801902144
0801902145
0801902146
0801902147
0801902148
0801902149
0801902015
0801902150
0801902151
0801902152
0801902153
0801902154
0801902155
0801902156
0801902157
0801902158
0801902159
0801902016
0801902160
0801902161
0801902162
0801902163
0801902164
0801902165
0801902166
0801902167
0801902168
0801902169
0801902017
0801902170
0801902171
0801902172
0801902173
0801902018
0801902019
0801902002
0801902020
0801902021
0801902022
0801902023
0801902024
0801902025
0801902026
0801902027
0801902028
0801902029
0801902003
0801902030
0801902031
0801902032
0801902033
0801902034
0801902035
0801902036
0801902037
0801902038
0801902039
0801902004
0801902040
0801902041
0801902042
0801902043
0801902044
0801902045
0801902046
0801902047
0801902048
0801902049
0801902005
0801902050
0801902051
0801902052
0801902053
0801902054
0801902055
0801902056
0801902057
0801902058
0801902059
0801902006
0801902060
0801902061
0801902062
0801902063
0801902064
0801902065
0801902066
0801902067
0801902068
0801902069
0801902007
0801902070
0801902071
0801902072
0801902073
0801902074
0801902075
0801902076
0801902077
0801902078
0801902079
0801902008
0801902080
0801902081
0801902082
0801902083
0801902084
0801902085
0801902086
0801902087
0801902088
0801902089
0801902009
0801902090
0801902091
0801902092
0801902093
0801902094
0801902095
0801902096
0801902097
0801902098
0801902099
0801903001
0801903010
0801903100
0801903101
0801903102
0801903103
0801903104
0801903105
0801903106
0801903107
0801903108
0801903109
0801903011
0801903110
0801903111
0801903112
0801903113
0801903114
0801903012
0801903013
0801903014
0801903015
0801903016
0801903017
0801903018
0801903019
0801903002
0801903020
0801903021
0801903211
0801903212
0801903213
0801903022
0801903023
0801903024
0801903025
0801903026
0801903027
0801903028
0801903029
0801903003
0801903030
0801903031
0801903032
0801903033
0801903034
0801903035
0801903036
0801903037
0801903038
0801903039
0801903004
0801903040
0801903041
0801903042
0801903043
0801903044
0801903045
0801903046
0801903047
0801903048
0801903049
0801903005
0801903050
0801903051
0801903052
0801903053
0801903054
0801903055
0801903056
0801903057
0801903058
0801903059
0801903006
0801903060
0801903061
0801903062
0801903063
0801903064
0801903065
0801903066
0801903067
0801903068
0801903069
0801903007
0801903070
0801903071
0801903072
0801903073
0801903074
0801903075
0801903076
0801903077
0801903078
0801903079
0801903008
0801903080
0801903081
0801903082
0801903083
0801903084
0801903085
0801903086
0801903087
0801903088
0801903089
0801903009
0801903090
0801903091
0801903092
0801903093
0801903094
0801903095
0801903096
0801903097
0801903098
0801903099
0801904001
0801904010
0801904011
0801904012
0801904013
0801904014
0801904015
0801904016
0801904017
0801904018
0801904019
0801904002
0801904020
0801904021
0801904022
0801904023
0801904024
0801904025
0801904026
0801904027
0801904028
0801904029
0801904003
0801904030
0801904031
0801904032
0801904033
0801904034
0801904035
0801904036
0801904037
0801904038
0801904039
0801904004
0801904040
0801904041
0801904042
0801904043
0801904044
0801904045
0801904046
0801904047
0801904048
0801904049
0801904005
0801904050
0801904051
0801904052
0801904053
0801904054
0801904055
0801904056
0801904006
0801904007
0801904008
0801904084
0801904009
0801905001
0801905010
0801905011
0801905012
0801905013
0801905014
0801905015
0801905016
0801905017
0801905018
0801905019
0801905002
0801905020
0801905021
0801905022
0801905023
0801905024
0801905025
0801905026
0801905027
0801905028
0801905029
0801905003
0801905030
0801905031
0801905032
0801905033
0801905034
0801905035
0801905036
0801905037
0801905038
0801905039
0801905004
0801905040
0801905041
0801905042
0801905043
0801905044
0801905045
0801905046
0801905047
0801905048
0801905049
0801905005
0801905050
0801905051
0801905052
0801905053
0801905054
0801905055
0801905056
0801905057
0801905058
0801905059
0801905006
0801905060
0801905061
0801905062
0801905063
0801905064
0801905065
0801905066
0801905067
0801905068
0801905069
0801905007
0801905070
0801905071
0801905072
0801905073
0801905074
0801905075
0801905076
0801905077
0801905078
0801905079
0801905008
0801905080
0801905081
0801905082
0801905083
0801905084
0801905085
0801905086
0801905087
0801905088
0801905089
0801905009
0801905090
0801905091
0801905092
0801905093
0801905094
0801905095
0801905096
0801905097
0801905098
0801906001
0801906010
0801906011
0801906012
0801906013
0801906014
0801906015
0801906016
0801906017
0801906018
0801906019
0801906002
0801906020
0801906021
0801906022
0801906023
0801906024
0801906025
0801906026
0801906027
0801906028
0801906029
0801906003
0801906030
0801906031
0801906032
0801906033
0801906034
0801906035
0801906036
0801906037
0801906038
0801906039
0801906004
0801906040
0801906041
0801906042
0801906043
0801906044
0801906045
0801906046
0801906047
0801906048
0801906049
0801906050
0801906051
0801906052
0801906053
0801906054
0801906055
0801906056
0801906057
0801906058
0801906059
0801906006
0801906060
0801906061
0801906062
0801906063
0801906064
0801906065
0801906066
0801906067
0801906068
0801906069
0801906007
0801906070
0801906071
0801906072
0801906073
0801906074
0801906075
0801906076
0801906077
0801906078
0801906079
0801906008
0801906080
0801906081
0801906082
0801906083
0801906084
0801906085
0801906086
0801906087
0801906088
0801906009
0801907001
0801907010
0801907100
0801907101
0801907102
0801907103
0801907104
0801907105
0801907106
0801907107
0801907108
0801907109
0801907011
0801907110
0801907111
0801907112
0801907113
0801907114
0801907115
0801907116
0801907117
0801907118
0801907119
0801907012
0801907120
0801907121
0801907122
0801907123
0801907013
0801907014
0801907015
0801907016
0801907017
0801907018
0801907019
0801907002
0801907020
0801907021
0801907022
0801907023
0801907024
0801907025
0801907026
0801907027
0801907028
0801907029
0801907003
0801907030
0801907031
0801907032
0801907033
0801907034
0801907035
0801907036
0801907037
0801907038
0801907039
0801907004
0801907040
0801907041
0801907042
0801907043
0801907044
0801907045
0801907046
0801907047
0801907048
0801907049
0801907005
0801907050
0801907051
0801907052
0801907053
0801907054
0801907055
0801907056
0801907057
0801907058
0801907059
0801907006
0801907060
0801907061
0801907062
0801907063
0801907064
0801907065
0801907066
0801907067
0801907068
0801907069
0801907007
0801907070
0801907071
0801907072
0801907073
0801907074
0801907075
0801907076
0801907077
0801907078
0801907079
0801907008
0801907080
0801907081
0801907082
0801907083
0801907084
0801907085
0801907086
0801907087
0801907088
0801907089
0801907009
0801907090
0801907091
0801907092
0801907093
0801907094
0801907095
0801907096
0801907097
0801907098
0801907099
0801908001
0801908010
0801908100
0801908101
0801908102
0801908103
0801908104
0801908105
0801908106
0801908107
0801908108
0801908109
0801908011
0801908110
0801908111
0801908112
0801908113
0801908114
0801908115
0801908116
0801908012
0801908013
0801908014
0801908015
0801908016
0801908017
0801908018
0801908019
0801908002
0801908020
0801908021
0801908215
0801908022
0801908023
0801908024
0801908025
0801908026
0801908027
0801908028
0801908029
0801908003
0801908030
0801908031
0801908032
0801908033
0801908034
0801908035
0801908036
0801908037
0801908038
0801908039
0801908004
0801908040
0801908041
0801908042
0801908043
0801908044
0801908045
0801908046
0801908047
0801908048
0801908049
0801908005
0801908050
0801908051
0801908052
0801908053
0801908054
0801908055
0801908056
0801908057
0801908058
0801908059
0801908006
0801908060
0801908061
0801908062
0801908063
0801908064
0801908065
0801908066
0801908067
0801908068
0801908069
0801908007
0801908070
0801908071
0801908072
0801908073
0801908074
0801908075
0801908076
0801908077
0801908078
0801908079
0801908008
0801908080
0801908081
0801908082
0801908083
0801908084
0801908085
0801908086
0801908087
0801908088
0801908089
0801908009
0801908090
0801908091
0801908092
0801908093
0801908094
0801908095
0801908096
0801908097
0801908098
0801908099
0801909001
0801909010
0801909011
0801909013
0801909014
0801909015
0801909156
0801909016
0801909017
0801909018
0801909019
0801909002
0801909020
0801909021
0801909022
0801909023
0801909024
0801909025
0801909026
0801909027
0801909028
0801909029
0801909003
0801909030
0801909031
0801909032
0801909033
0801909034
0801909035
0801909036
0801909037
0801909038
0801909039
0801909004
0801909040
0801909041
0801909042
0801909043
0801909044
0801909045
0801909046
0801909047
0801909048
0801909049
0801909005
0801909050
0801909051
0801909052
0801909053
0801909054
0801909055
0801909056
0801909057
0801909058
0801909059
0801909006
0801909060
0801909061
0801909062
0801909063
0801909064
0801909065
0801909066
0801909067
0801909068
0801909069
0801909007
0801909070
0801909071
0801909072
0801909073
0801909074
0801909075
0801909076
0801909077
0801909078
0801909079
0801909008
0801909080
0801909081
0801909082
0801909083
0801909084
0801909085
0801909086
0801909087
0801909088
0801909089
0801909009
0801909090
0801909091
0801909092
0801909093
0801909094
0801909095
0802001001
0802001002
0802001003
0802301001
0802301002
0802301003
0802301004
0802301005
0802701001
0802901001
0802901002
0803001001
0803001002
0803201001
0803301001
0803301002
0803301003
0803302001
0803303001
0803303002
0803303003
0803303004
0803303005
0803501001
0803501002
0803501003
0803502001
0803502002
0803503001
0803503002
0803503003
0803503004
0803901001
0804001001
0804001002
0804001003
0804001004
0804001005
0804001006
0804001007
0804001008
0804101001
0804101002
0804101003
0804101004
0804101005
0804101006
0804101007
0804101008
0804301001
0804301002
0804601001
0804601002
0804601003
0804602001
0804602002
0804602003
0804602004
0804603001
0805101001
0805101010
0805101011
0805101012
0805101013
0805101014
0805101002
0805101003
0805101004
0805101005
0805101006
0805101007
0805101008
0805101009
0805401001
0805401002
0805401003
0805401004
0805401005
0805401006
0805601001
0805601002
0805601003
0805601004
0805601005
0805601006
0805601007
0805602001
0805602002
0805602003
0805602004
0805602005
0805602006
0805603001
0805603002
0805603003
0805603004
0805603005
0805604001
0805604002
0805604003
0805604004
0805605001
0805605002
0805605003
0805605004
0805801001
0806601001
0806501001
0826601001
0826601010
0826601011
0826601012
0826601013
0826601014
0826601015
0826601016
0826601017
0826601018
0826601019
0826601002
0826601020
0826601027
0826601028
0826601029
0826601003
0826601030
0826601031
0826601032
0826601033
0826601034
0826601035
0826601036
0826601037
0826601038
0826601004
0826601005
0826601006
0826601007
0826601008
0826601009
0806801001
0806801002
0806801003
0806801004
0806801005
0806901001
0806901003
0807201001
0807201010
0807201011
0807201002
0807201003
0807201004
0807201005
0807201006
0807201007
0807201008
0807201009
0807401001
0807401010
0807401002
0807401003
0807401004
0807401005
0807401006
0807401007
0807401008
0807401009
0804201001
0807501001
0807501002
0807501003
0807601001
0807601002
0807601003
0807601004
0807601005
0807601006
0807602001
0807602002
0807602003
0807602004
0807602005
0813401001
0808101001
0808501001
0808601001
0808601002
0808601003
0808601004
0808601005
0808601006
0808601007
0808602001
0808701001
0808801001
0808801002
0808801003
0808802001
0808802002
0808802003
0808802004
0808901001
0808901002
0808901003
0808901004
0808901005
0808901006
0808901007
0808901008
0808902001
0808902010
0808902002
0808902003
0808902004
0808902005
0808902006
0808902007
0808902008
0808902009
0808903001
0808903002
0808903003
0808903004
0808903005
0808903006
0808903007
0808903008
0808904001
0808904002
0809101001
0809101002
0809102001
0809401001
0809601001
0809601010
0809601011
0809601003
0809601004
0809601005
0809601006
0809601009
0809602001
0809602002
0809602003
0809602004
0809602005
0809602006
0809602007
0809603001
0809603010
0809603002
0809603003
0809603004
0809603005
0809603006
0809603007
0809603008
0809603009
0809604001
0809604010
0809604011
0809604002
0809604003
0809604004
0809604006
0809604007
0809604008
0809604009
0809701001
0810103026
0810103027
0810501001
0810501002
0810501003
0810501004
0810501005
0810501006
0810501007
0810501008
0810501009
0810601001
0810601002
0810602001
0810602002
0810602003
0810602004
0810701001
0810701010
0810701002
0810701003
0810701004
0810701005
0810701006
0810701007
0810701008
0810701009
0810801001
0810801002
0810801003
0810801004
0811001001
0811001002
0811001003
0811001004
0811001005
0811001006
0811002001
0811002002
0811002003
0811401001
0811401002
0811401003
0811402003
0811403010
0811403002
0811403004
0811403005
0811403006
0811403007
0811403008
0811404001
0811404002
0811404003
0811404004
0811501001
0811501002
0811501003
0811801001
0811801010
0811801002
0811801003
0811801004
0811801005
0811801006
0811801007
0811801008
0811801009
0811802001
0811802002
0811802003
0811802004
0812001001
0812001002
0812001003
0812001004
0812101001
0812101002
0812101003
0812101004
0812101005
0812101006
0812101007
0812101009
0812102001
0812102010
0812102011
0812102012
0812102002
0812102003
0812102004
0812102005
0812102007
0812102008
0812102009
0812103001
0812103010
0812103011
0812103012
0812103013
0812103014
0812103002
0812103003
0812103004
0812103005
0812103006
0812103007
0812103008
0812103009
0812104001
0812104002
0812104003
0812104004
0812104005
0812104006
0812104007
0812104008
0812104009
0812105001
0812105010
0812105011
0812105012
0812105013
0812105015
0812105016
0812105017
0812105019
0812105002
0812105020
0812105021
0812105003
0812105004
0812105005
0812105006
0812105007
0812105008
0812105009
0812106001
0812106010
0812106011
0812106012
0812106013
0812106014
0812106002
0812106003
0812106004
0812106005
0812106006
0812106007
0812106008
0812106009
0812201001
0812301001
0812301002
0812301003
0812302001
0812302002
0812302003
0812302004
0812303001
0812303002
0812303003
0812303004
0812304001
0812401001
0812401002
0812401003
0812401004
0812401005
0812401006
0812401007
0812402001
0812402002
0812402003
0812402004
0812402005
0812402006
0812402007
0812402008
0812402009
0812403001
0812403010
0812403011
0812403012
0812403013
0812403014
0812403015
0812403002
0812403003
0812403004
0812403005
0812403006
0812403007
0812403008
0812403009
0812501001
0812501002
0812501004
0812501005
0812502001
0812502002
0812502003
0812503001
0812503002
0812503003
0812503004
0812503005
0812503006
0812504001
0812504002
0812504003
0812505001
0812505002
0812505003
0812506001
0812506002
0812506003
0812601001
0812601002
0812601003
0812601004
0813501001
0813501002
0813501003
0813501004
0813501005
0813601001
0813601002
0813601003
0813601004
0813601005
0813601006
0813601007
0813602001
0813602002
0813602003
0813701001
0814601001
0814601002
0814701001
0814701010
0814701011
0814701002
0814701003
0814701004
0814701005
0814701006
0814701007
0814701008
0814701009
0814801001
0814801002
0814501001
0814501002
0815401001
0815501001
0815501002
0815501003
0815501004
0815501005
0815601001
0815601002
0815601003
0815601004
0815601005
0815601006
0815601007
0815601008
0815701001
0815701002
0815701003
0815701004
0815701005
0890501001
0890501002
0815801001
0815801002
0815901001
0815901002
0815901003
0815901004
0815902001
0815902002
0815902003
0815902004
0815902005
0815902006
0815902007
0816301001
0816301010
0816301011
0816301012
0816301013
0816301014
0816301002
0816301003
0816301004
0816301005
0816301006
0816301007
0816301008
0816301009
0816401001
0816701001
0816701002
0816701003
0816701004
0816801001
0816901001
0816901002
0816901003
0816901004
0816901005
0816902001
0816902002
0816902003
0816902004
0816902005
0816902006
0816902007
0816903001
0816903010
0816903011
0816903012
0816903013
0816903002
0816903003
0816903004
0816903005
0816903006
0816903007
0816903008
0816903009
0816904001
0816904002
0816904003
0816904004
0816904005
0816904006
0816905001
0816905002
0816905003
0816905004
0816905005
0816905006
0816905007
0816905008
0816905009
0823001001
0823001002
0823001003
0823001004
0823001005
0823001006
0817201001
0817201002
0817201003
0817202001
0817202002
0817202003
0817202004
0817203001
0817203002
0817203003
0817203004
0817203005
0817203006
0817203007
0817203008
0817203009
0817401001
0817901001
0818001001
0818001010
0818001011
0818001012
0818001013
0818001002
0818001003
0818001004
0818001005
0818001006
0818001007
0818001008
0818001009
0818002001
0818002002
0818002003
0818002004
0818002005
0818002006
0818002007
0818101001
0818101002
0818101003
0818101004
0818101005
0818401001
0818401002
0818401003
0818401004
0818402001
0818402003
0818402004
0818402005
0818402006
0818403001
0818403003
0818403004
0818403005
0818403006
0818403007
0818403008
0818403009
0818404001
0818404010
0818404011
0818404012
0818404013
0818404014
0818404015
0818404016
0818404018
0818404019
0818404002
0818404020
0818404021
0818404022
0818404023
0818404024
0818404025
0818404026
0818404003
0818404004
0818404005
0818404006
0818404007
0818404008
0818404009
0818701001
0818701010
0818701011
0818701012
0818701013
0818701014
0818701015
0818701016
0818701017
0818701018
0818701019
0818701002
0818701020
0818701021
0818701022
0818701023
0818701024
0818701025
0818701026
0818701027
0818701028
0818701029
0818701003
0818701030
0818701031
0818701032
0818701033
0818701034
0818701035
0818701004
0818701005
0818701006
0818701007
0818701008
0818701009
0818702001
0818702010
0818702011
0818702012
0818702013
0818702014
0818702015
0818702016
0818702017
0818702002
0818702003
0818702004
0818702005
0818702006
0818702007
0818702008
0818702009
0818703001
0818703010
0818703011
0818703012
0818703013
0818703014
0818703015
0818703016
0818703017
0818703018
0818703019
0818703002
0818703020
0818703021
0818703022
0818703023
0818703024
0818703025
0818703026
0818703027
0818703003
0818703004
0818703005
0818703006
0818703007
0818703008
0818703009
0818704001
0818704010
0818704011
0818704012
0818704013
0818704014
0818704015
0818704016
0818704017
0818704018
0818704019
0818704002
0818704020
0818704021
0818704022
0818704023
0818704024
0818704025
0818704026
0818704027
0818704028
0818704029
0818704003
0818704004
0818704005
0818704006
0818704007
0818704008
0818704009
0818705001
0818705011
0818705012
0818705013
0818705014
0818705015
0818705002
0818705003
0818705004
0818705005
0818705006
0818705007
0818705008
0818705009
0818706001
0818706010
0818706011
0818706012
0818706013
0818706014
0818706016
0818706017
0818706018
0818706002
0818706020
0818706021
0818706022
0818706023
0818706024
0818706003
0818706004
0818706005
0818706006
0818706007
0818706008
0818706009
0818707001
0818707002
0818707003
0818707004
0818707005
0818707006
0818707007
0818707008
0819401001
0819401002
0819401003
0819401004
0819401005
0819401006
0819402001
0819402002
0819402003
0819402004
0819402005
0819403001
0819404001
0819405001
0819405002
0819405003
0819405004
0819406001
0819406002
0819406003
0819406004
0819406005
0819406006
0819406007
0819701001
0819701002
0819701003
0819702001
0819702002
0819702003
0819601001
0819601010
0819601011
0819601012
0819601013
0819601014
0819601002
0819601003
0819601004
0819601005
0819601006
0819601007
0819601008
0819601009
0819801001
0819801002
0819801003
0819801004
0820001001
0820001002
0820001003
0820001004
0820001005
0820001006
0820001007
0820002001
0820002010
0820002011
0820002012
0820002013
0820002014
0820002015
0820002016
0820002017
0820002018
0820002019
0820002002
0820002003
0820002004
0820002005
0820002006
0820002007
0820002008
0820002009
0820003001
0820003002
0820003003
0820003004
0820003005
0820003006
0820003007
0820003008
0820003009
0820004001
0820004002
0820004003
0820004004
0820004005
0820004006
0820004007
0820004008
0820004009
0820005001
0820005002
0820005003
0820006001
0820006002
0820006003
0820301001
0820301002
0820201001
0820201002
0820201003
0820201004
0820201005
0820201006
0820201007
0820201008
0820202001
0820401001
0820401002
0820601001
0820501001
0820501010
0820501011
0820501012
0820501013
0820501014
0820501015
0820501016
0820501017
0820501018
0820501019
0820501002
0820501020
0820501021
0820501022
0820501023
0820501003
0820501004
0820501005
0820501006
0820501007
0820501008
0820501009
0820502001
0820502010
0820502011
0820502012
0820502002
0820502003
0820502004
0820502005
0820502006
0820502007
0820502008
0820502009
0820503001
0820503002
0820503003
0820503004
0820504001
0820504002
0820504003
0820505001
0820505002
0820505003
0820505004
0820505005
0820505006
0820505007
0820505008
0820506001
0820801001
0820801002
0820801003
0820801004
0820701001
0821001001
0821001002
0821002001
0821002002
0821101001
0821101002
0821101003
0821101004
0821101005
0821101006
0821101007
0821102003
0821102004
0821102006
0821102007
0821102008
0821103001
0821103002
0821103003
0821103004
0821103005
0821104003
0821104006
0821104007
0821104008
0821105001
0821105002
0821105003
0821105004
0821105005
0821106004
0821107001
0821107002
0821107003
0820901001
0820901002
0820901003
0820901004
0819301001
0821701001
0821701010
0821701002
0821701003
0821701004
0821701005
0821701006
0821701007
0821701008
0821701009
0821702002
0821702003
0821702004
0821703001
0821703002
0821703003
0821703004
0821703005
0821704001
0821705001
0821705002
0822101001
0822101002
0822101003
0822101004
0822101005
0822101006
0822101007
0822101008
0822101009
0822301001
0822201001
0822701001
0822701002
0823101001
0823101010
0823101011
0823101012
0823101013
0823101014
0823101015
0823101016
0823101017
0823101002
0823101003
0823101004
0823101005
0823101006
0823101007
0823101008
0823101009
0823201001
0823401001
0823501001
0823501002
0823501003
0823601001
0823801001
0823801010
0823801011
0823801012
0823801002
0823801003
0823801004
0823801005
0823801006
0823801007
0823801008
0823801009
0824001001
0824001002
0824001003
0824001004
0824002001
0824002002
0824002003
0824002004
0826401001
0826401002
0826401003
0826401004
0826301001
0826301010
0826301011
0826301012
0826301002
0826301003
0826301004
0826301005
0826301006
0826301007
0826301008
0826301009
0826302001
0826302002
0826302003
0826303001
0826303002
0826304001
0826304002
0826304003
0824401001
0824401002
0824401003
0824401004
0824401005
0824501001
0824501010
0824501011
0824501012
0824501013
0824501014
0824501015
0824501016
0824501017
0824501018
0824501019
0824501002
0824501003
0824501004
0824501005
0824501006
0824501007
0824501008
0824501009
0824502001
0824502010
0824502011
0824502002
0824502003
0824502004
0824502005
0824502006
0824502007
0824502008
0824502009
0824503001
0824503010
0824503011
0824503012
0824503013
0824503014
0824503015
0824503016
0824503017
0824503002
0824503003
0824503004
0824503005
0824503006
0824503007
0824503008
0824503009
0824504001
0824504010
0824504011
0824504012
0824504013
0824504014
0824504015
0824504016
0824504002
0824504003
0824504004
0824504005
0824504006
0824504007
0824504008
0824504009
0824505001
0824505010
0824505011
0824505012
0824505013
0824505014
0824505015
0824505016
0824505017
0824505018
0824505019
0824505002
0824505003
0824505004
0824505005
0824505006
0824505007
0824505008
0824505009
0824506001
0824506010
0824506011
0824506012
0824506013
0824506014
0824506015
0824506016
0824506017
0824506002
0824506003
0824506004
0824506005
0824506006
0824506007
0824506008
0824506009
0824801001
0824801002
0824901001
0825101001
0825101002
0825101003
0825101004
0825601001
0825901001
0825901002
0825901003
0825901004
0826001001
0826001010
0826001011
0826001012
0826001013
0826001014
0826001002
0826001003
0826001004
0826001005
0826001006
0826001007
0826001008
0826001009
0826101001
0826101002
0826701001
0826701002
0826701003
0826701004
0826701005
0827001001
0827001002
0827001003
0827001004
0827001005
0827002001
0827002010
0827002011
0827002002
0827002003
0827002004
0827002005
0827002006
0827002007
0827002009
0827301001
0827301002
0827301003
0827601001
0828101001
0828101002
0828101003
0827901001
0827901010
0827901011
0827901012
0827901013
0827901014
0827901015
0827901016
0827901017
0827901018
0827901019
0827901002
0827901020
0827901021
0827901022
0827901023
0827901024
0827901004
0827901005
0827901006
0827901007
0827901008
0827901009
0827902001
0827902011
0827902012
0827902014
0827902015
0827902016
0827902017
0827902002
0827902003
0827902004
0827902005
0827902006
0827902008
0827902009
0827903001
0827903010
0827903011
0827903012
0827903014
0827903015
0827903016
0827903017
0827903018
0827903019
0827903002
0827903020
0827903003
0827903004
0827903005
0827903006
0827903007
0827903008
0827903009
0827904001
0827904010
0827904012
0827904013
0827904014
0827904015
0827904016
0827904017
0827904018
0827904019
0827904002
0827904020
0827904021
0827904022
0827904023
0827904024
0827904025
0827904026
0827904003
0827904004
0827904005
0827904006
0827904007
0827904008
0827904009
0827905001
0827905010
0827905011
0827905012
0827905013
0827905014
0827905015
0827905016
0827905017
0827905018
0827905019
0827905002
0827905020
0827905021
0827905022
0827905023
0827905024
0827905025
0827905026
0827905027
0827905028
0827905029
0827905003
0827905004
0827905005
0827905006
0827905007
0827905008
0827905009
0827906001
0827906010
0827906011
0827906012
0827906013
0827906014
0827906016
0827906018
0827906002
0827906020
0827906023
0827906024
0827906025
0827906026
0827906027
0827906028
0827906029
0827906003
0827906030
0827906031
0827906032
0827906033
0827906004
0827906005
0827906006
0827906008
0827906009
0828201001
0828201002
0828201003
0828201004
0828201005
0828401001
0828401002
0828401003
0828401004
0828402001
0828402002
0828402003

In [9]:
## Votos 2015
####################
df = []
u_cusec = votos2015['CUSEC'].unique()
for cusec_i in u_cusec:
    df.append(votos2015.loc[(votos2015['CUSEC'] == cusec_i), :].iloc[:, 1:].sum(0))
votos2015 = pd.concat([pd.DataFrame(u_cusec, columns=['CUSEC']), pd.DataFrame(df)], axis=1)

In [23]:
data2015.loc[data2015['Codi Municipi'] == 8073]


Out[23]:
Codi Prov�ncia Nom Prov�ncia Codi Vegueria Nom Vegueria Codi Comarca Nom Comarca Codi Municipi Nom Municipi Districte Secci� ... unio.cat Vots unio.cat Diputats CUP Vots CUP Diputats RECORTES 0-EV Vots RECORTES 0-EV Diputats PIRATA.CAT/XDT Vots PIRATA.CAT/XDT Diputats GANEMOS Vots GANEMOS Diputats
2036 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 1 ... 21 0 76 0 0 0 0 0 0 0
2037 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 1 ... 10 0 69 0 3 0 0 0 0 0
2038 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 10 ... 7 0 27 0 1 0 0 0 0 0
2039 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 10 ... 8 0 41 0 2 0 0 0 0 0
2040 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 11 ... 4 0 25 0 0 0 0 0 0 0
2041 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 11 ... 4 0 24 0 1 0 0 0 0 0
2042 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 12 ... 5 0 38 0 2 0 0 0 0 0
2043 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 13 ... 11 0 29 0 5 0 0 0 0 0
2044 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 13 ... 12 0 30 0 3 0 0 0 0 0
2045 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 14 ... 12 0 83 0 2 0 0 0 0 0
2046 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 2 ... 10 0 50 0 0 0 0 0 0 0
2047 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 2 ... 7 0 42 0 1 0 0 0 0 0
2048 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 3 ... 3 0 20 0 4 0 0 0 0 0
2049 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 3 ... 7 0 31 0 2 0 0 0 0 0
2050 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 4 ... 9 0 36 0 5 0 0 0 0 0
2051 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 4 ... 10 0 45 0 7 0 0 0 0 0
2052 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 5 ... 16 0 60 0 5 0 0 0 0 0
2053 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 6 ... 9 0 55 0 3 0 0 0 0 0
2054 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 7 ... 11 0 62 0 2 0 0 0 0 0
2055 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 7 ... 18 0 78 0 4 0 0 0 0 0
2056 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 8 ... 8 0 50 0 3 0 0 0 0 0
2057 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 8 ... 3 0 53 0 6 0 0 0 0 0
2058 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 9 ... 5 0 29 0 2 0 0 0 0 0
2059 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 1 9 ... 2 0 31 0 3 0 0 0 0 0
2060 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 2 1 ... 15 0 47 0 2 0 0 0 0 0
2061 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 2 1 ... 11 0 39 0 3 0 0 0 0 0
2062 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 2 1 ... 22 0 48 0 0 0 0 0 0 0
2063 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 2 2 ... 8 0 24 0 5 0 0 0 0 0
2064 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 2 2 ... 12 0 24 0 3 0 0 0 0 0
2065 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 2 2 ... 11 0 31 0 4 0 0 0 0 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2121 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 5 3 ... 1 0 8 0 2 0 0 0 0 0
2122 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 5 4 ... 6 0 10 0 6 0 0 0 0 0
2123 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 5 5 ... 5 0 15 0 5 0 0 0 0 0
2124 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 5 6 ... 4 0 5 0 1 0 0 0 0 0
2125 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 5 6 ... 2 0 18 0 3 0 0 0 0 0
2126 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 5 7 ... 1 0 6 0 1 0 0 0 0 0
2127 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 5 7 ... 1 0 8 0 3 0 0 0 0 0
2128 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 5 8 ... 1 0 4 0 1 0 0 0 0 0
2129 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 5 8 ... 2 0 9 0 6 0 0 0 0 0
2130 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 5 9 ... 1 0 30 0 6 0 0 0 0 0
2131 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 1 ... 2 0 10 0 1 0 0 0 0 0
2132 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 10 ... 1 0 9 0 3 0 0 0 0 0
2133 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 11 ... 2 0 13 0 1 0 0 0 0 0
2134 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 12 ... 7 0 9 0 2 0 0 0 0 0
2135 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 13 ... 4 0 10 0 4 0 0 0 0 0
2136 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 14 ... 3 0 10 0 4 0 0 0 0 0
2137 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 15 ... 4 0 21 0 6 0 0 0 0 0
2138 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 16 ... 7 0 5 0 5 0 0 0 0 0
2139 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 2 ... 0 0 5 0 2 0 0 0 0 0
2140 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 2 ... 2 0 4 0 3 0 0 0 0 0
2141 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 3 ... 3 0 5 0 2 0 0 0 0 0
2142 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 4 ... 0 0 10 0 1 0 0 0 0 0
2143 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 5 ... 3 0 9 0 0 0 0 0 0 0
2144 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 6 ... 6 0 11 0 3 0 0 0 0 0
2145 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 7 ... 6 0 1 0 1 0 0 0 0 0
2146 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 7 ... 3 0 14 0 0 0 0 0 0 0
2147 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 8 ... 4 0 6 0 5 0 0 0 0 0
2148 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 9 ... 3 0 12 0 1 0 0 0 0 0
2149 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 9 ... 3 0 8 0 1 0 0 0 0 0
2150 8 Barcelona 1 Barcelona 11 Baix Llobregat 8073 Cornell� de Llobregat 6 9 ... 5 0 8 0 0 0 0 0 0 0

115 rows × 42 columns


In [13]:
df = []
u_cusec = votos2015['CUSEC'].unique()
for cusec_i in u_cusec:
    df.append(data2015.iloc[:, 19][(data2015['CUSEC'] == cusec_i)].sum(0))
summary_ind_2015 =\
    pd.concat([pd.DataFrame(u_cusec, columns=['CUSEC']),
               pd.DataFrame(pd.Series(df), columns=['VotosValidos']),
               pd.DataFrame(votos2015[["JxSi", "CUP"]].sum(1), columns=['Pro_ind_votos'])],
              axis=1)
summary_ind_2015['Pro_ind'] =\
    summary_ind_2015['Pro_ind_votos']/summary_ind_2015['VotosValidos']


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-13-739e3630466a> in <module>()
      2 u_cusec = votos2015['CUSEC'].unique()
      3 for cusec_i in u_cusec:
----> 4     df.append(data2015.iloc[:, 19][(data2015['CUSEC'] == cusec_i)].sum(0))
      5 summary_ind_2015 =    pd.concat([pd.DataFrame(u_cusec, columns=['CUSEC']),
      6                pd.DataFrame(pd.Series(df), columns=['VotosValidos']),

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in __getitem__(self, key)
   2057             return self._getitem_multilevel(key)
   2058         else:
-> 2059             return self._getitem_column(key)
   2060 
   2061     def _getitem_column(self, key):

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _getitem_column(self, key)
   2064         # get column
   2065         if self.columns.is_unique:
-> 2066             return self._get_item_cache(key)
   2067 
   2068         # duplicate columns & possible reduce dimensionality

/usr/local/lib/python2.7/dist-packages/pandas/core/generic.pyc in _get_item_cache(self, item)
   1384         res = cache.get(item)
   1385         if res is None:
-> 1386             values = self._data.get(item)
   1387             res = self._box_item_values(item, values)
   1388             cache[item] = res

/usr/local/lib/python2.7/dist-packages/pandas/core/internals.pyc in get(self, item, fastpath)
   3541 
   3542             if not isnull(item):
-> 3543                 loc = self.items.get_loc(item)
   3544             else:
   3545                 indexer = np.arange(len(self.items))[isnull(self.items)]

/usr/local/lib/python2.7/dist-packages/pandas/indexes/base.pyc in get_loc(self, key, method, tolerance)
   2134                 return self._engine.get_loc(key)
   2135             except KeyError:
-> 2136                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   2137 
   2138         indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4433)()

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4279)()

pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13742)()

pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13696)()

KeyError: 'CUSEC'

In [ ]:
summary_ind_2015_trio = pd.merge(data_censo[['CUSEC']], summary_ind_2015, how='left')

In [292]:
summary_ind_2015_trio[pd.isnull(summary_ind_2015_trio).any(1)]


Out[292]:
CUSEC VotosValidos Pro_ind_votos Pro_ind
141 0810102003 NaN NaN NaN
144 0810102006 NaN NaN NaN
153 0810102015 NaN NaN NaN
156 0810102018 NaN NaN NaN
157 0810102019 NaN NaN NaN
160 0810102022 NaN NaN NaN
163 0810102025 NaN NaN NaN
165 0810102027 NaN NaN NaN
168 0810102030 NaN NaN NaN
173 0810102035 NaN NaN NaN
179 0810102041 NaN NaN NaN
182 0810102044 NaN NaN NaN
220 0810104008 NaN NaN NaN
225 0810104013 NaN NaN NaN
227 0810104015 NaN NaN NaN
229 0810104017 NaN NaN NaN
236 0810104024 NaN NaN NaN
240 0810104028 NaN NaN NaN
241 0810104029 NaN NaN NaN
246 0810104034 NaN NaN NaN
250 0810104038 NaN NaN NaN
251 0810104039 NaN NaN NaN
254 0810104042 NaN NaN NaN
263 0810105009 NaN NaN NaN
266 0810105012 NaN NaN NaN
269 0810105015 NaN NaN NaN
270 0810105016 NaN NaN NaN
273 0810105019 NaN NaN NaN
276 0810105022 NaN NaN NaN
281 0810105027 NaN NaN NaN
290 0810105036 NaN NaN NaN
295 0810106003 NaN NaN NaN
296 0810106004 NaN NaN NaN
312 0810106020 NaN NaN NaN
320 0810106028 NaN NaN NaN
321 0810106029 NaN NaN NaN

In [83]:
m = folium.Map([41.37, 2.1], tiles='cartodbpositron', zoom_start=13)

m.choropleth(
    geo_data=file_geojson,
    data=pro_ind,
    columns=['CUSEC', 'Pro_ind'],
    key_on='feature.properties.CUSEC',
    fill_color='YlGn',
    highlight=True,
    )
m


Out[83]:

In [67]:
help(m.choropleth)


Help on method choropleth in module folium.folium:

choropleth(self, geo_data, data=None, columns=None, key_on=None, threshold_scale=None, fill_color='blue', fill_opacity=0.6, line_color='black', line_weight=1, line_opacity=1, name=None, legend_name='', topojson=None, reset=False, smooth_factor=None, highlight=None) method of folium.folium.Map instance
    Apply a GeoJSON overlay to the map.
    
    Plot a GeoJSON overlay on the base map. There is no requirement
    to bind data (passing just a GeoJSON plots a single-color overlay),
    but there is a data binding option to map your columnar data to
    different feature objects with a color scale.
    
    If data is passed as a Pandas DataFrame, the "columns" and "key-on"
    keywords must be included, the first to indicate which DataFrame
    columns to use, the second to indicate the layer in the GeoJSON
    on which to key the data. The 'columns' keyword does not need to be
    passed for a Pandas series.
    
    Colors are generated from color brewer (http://colorbrewer2.org/)
    sequential palettes on a D3 threshold scale. The scale defaults to the
    following quantiles: [0, 0.5, 0.75, 0.85, 0.9]. A custom scale can be
    passed to `threshold_scale` of length <=6, in order to match the
    color brewer range.
    
    TopoJSONs can be passed as "geo_data", but the "topojson" keyword must
    also be passed with the reference to the topojson objects to convert.
    See the topojson.feature method in the TopoJSON API reference:
    https://github.com/topojson/topojson/wiki/API-Reference
    
    
    Parameters
    ----------
    geo_data: string/object
        URL, file path, or data (json, dict, geopandas, etc) to your GeoJSON geometries
    data: Pandas DataFrame or Series, default None
        Data to bind to the GeoJSON.
    columns: dict or tuple, default None
        If the data is a Pandas DataFrame, the columns of data to be bound.
        Must pass column 1 as the key, and column 2 the values.
    key_on: string, default None
        Variable in the GeoJSON file to bind the data to. Must always
        start with 'feature' and be in JavaScript objection notation.
        Ex: 'feature.id' or 'feature.properties.statename'.
    threshold_scale: list, default None
        Data range for D3 threshold scale. Defaults to the following range
        of quantiles: [0, 0.5, 0.75, 0.85, 0.9], rounded to the nearest
        order-of-magnitude integer. Ex: 270 rounds to 200, 5600 to 6000.
    fill_color: string, default 'blue'
        Area fill color. Can pass a hex code, color name, or if you are
        binding data, one of the following color brewer palettes:
        'BuGn', 'BuPu', 'GnBu', 'OrRd', 'PuBu', 'PuBuGn', 'PuRd', 'RdPu',
        'YlGn', 'YlGnBu', 'YlOrBr', and 'YlOrRd'.
    fill_opacity: float, default 0.6
        Area fill opacity, range 0-1.
    line_color: string, default 'black'
        GeoJSON geopath line color.
    line_weight: int, default 1
        GeoJSON geopath line weight.
    line_opacity: float, default 1
        GeoJSON geopath line opacity, range 0-1.
    legend_name: string, default empty string
        Title for data legend.
    topojson: string, default None
        If using a TopoJSON, passing "objects.yourfeature" to the topojson
        keyword argument will enable conversion to GeoJSON.
    reset: boolean, default False
        Remove all current geoJSON layers, start with new layer
    smooth_factor: float, default None
        How much to simplify the polyline on each zoom level. More means
        better performance and smoother look, and less means more accurate
        representation. Leaflet defaults to 1.0.
    highlight: boolean, default False
        Enable highlight functionality when hovering over a GeoJSON area.
    
    Returns
    -------
    GeoJSON data layer in obj.template_vars
    
    Examples
    --------
    >>> m.choropleth(geo_data='us-states.json', line_color='blue',
    ...              line_weight=3)
    >>> m.choropleth(geo_data='geo.json', data=df,
    ...              columns=['Data 1', 'Data 2'],
    ...              key_on='feature.properties.myvalue',
    ...              fill_color='PuBu',
    ...              threshold_scale=[0, 20, 30, 40, 50, 60])
    >>> m.choropleth(geo_data='countries.json',
    ...              topojson='objects.countries')
    >>> m.choropleth(geo_data='geo.json', data=df,
    ...              columns=['Data 1', 'Data 2'],
    ...              key_on='feature.properties.myvalue',
    ...              fill_color='PuBu',
    ...              threshold_scale=[0, 20, 30, 40, 50, 60],
    ...              highlight=True)


In [72]:
help(m.add_child)


Help on method add_to in module branca.element:

add_to(self, parent, name=None, index=None) method of folium.folium.Map instance
    Add element to a parent.


In [89]:
#m._children['geo_json_79b9e4e8b7304fa59ba9b0397992e40a']
#m._children['color_map_15da5ba0b18b4e248a9a7c24dd9fad04']
a = m._children['geo_json_79b9e4e8b7304fa59ba9b0397992e40a']


Out[89]:
OrderedDict()

In [76]:
m = folium.Map([41.37, 2.1], tiles='cartodbpositron', zoom_start=13)

folium.RegularPolygonMarker
folium.

In [99]:
m = folium.Map([41.37, 2.1], tiles='cartodbpositron', zoom_start=13)

geo_cens = folium.folium.GeoJson(file_geojson, style_function=None,
                                 highlight_function=None, overlay=True, control=False)
geo_cens.add_to(m, 'regiones_censales')
m


Out[99]:

In [97]:
help(folium.folium.GeoJson)


Help on class GeoJson in module folium.features:

class GeoJson(folium.map.Layer)
 |  Creates a GeoJson object for plotting into a Map.
 |  
 |  Parameters
 |  ----------
 |  data: file, dict or str.
 |      The GeoJSON data you want to plot.
 |      * If file, then data will be read in the file and fully
 |      embedded in Leaflet's JavaScript.
 |      * If dict, then data will be converted to JSON and embedded
 |      in the JavaScript.
 |      * If str, then data will be passed to the JavaScript as-is.
 |  style_function: function, default None
 |      Function mapping a GeoJson Feature to a style dict.
 |  highlight_function: function, default None
 |      Function mapping a GeoJson Feature to a style dict for mouse events.
 |  name : string, default None
 |      The name of the Layer, as it will appear in LayerControls
 |  overlay : bool, default False
 |      Adds the layer as an optional overlay (True) or the base layer (False).
 |  control : bool, default True
 |      Whether the Layer will be included in LayerControls
 |  smooth_factor: float, default None
 |      How much to simplify the polyline on each zoom level. More means
 |      better performance and smoother look, and less means more accurate
 |      representation. Leaflet defaults to 1.0.
 |  
 |  Examples
 |  --------
 |  >>> # Providing file that shall be embedded.
 |  >>> GeoJson(open('foo.json'))
 |  >>> # Providing filename that shall not be embedded.
 |  >>> GeoJson('foo.json')
 |  >>> # Providing dict.
 |  >>> GeoJson(json.load(open('foo.json')))
 |  >>> # Providing string.
 |  >>> GeoJson(open('foo.json').read())
 |  
 |  >>> # Provide a style_function that color all states green but Alabama.
 |  >>> style_function = lambda x: {'fillColor': '#0000ff' if
 |  ...                             x['properties']['name']=='Alabama' else
 |  ...                             '#00ff00'}
 |  >>> GeoJson(geojson, style_function=style_function)
 |  
 |  Method resolution order:
 |      GeoJson
 |      folium.map.Layer
 |      branca.element.MacroElement
 |      branca.element.Element
 |      __builtin__.object
 |  
 |  Methods defined here:
 |  
 |  __init__(self, data, style_function=None, name=None, overlay=True, control=True, smooth_factor=None, highlight_function=None)
 |  
 |  style_data(self)
 |      Applies `self.style_function` to each feature of `self.data` and
 |      returns a corresponding JSON output.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from branca.element.MacroElement:
 |  
 |  render(self, **kwargs)
 |      Renders the HTML representation of the element.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from branca.element.Element:
 |  
 |  add_child(self, child, name=None, index=None)
 |      Add a child.
 |  
 |  add_children(self, child, name=None, index=None)
 |      Add a child.
 |  
 |  add_to(self, parent, name=None, index=None)
 |      Add element to a parent.
 |  
 |  get_bounds(self)
 |      Computes the bounds of the object and all it's children
 |      in the form [[lat_min, lon_min], [lat_max, lon_max]].
 |  
 |  get_name(self)
 |      Returns a string representation of the object.
 |      This string has to be unique and to be a python and
 |      javascript-compatible
 |      variable name.
 |  
 |  get_root(self)
 |      Returns the root of the elements tree.
 |  
 |  save(self, outfile, close_file=True, **kwargs)
 |      Saves an Element into a file.
 |      
 |      Parameters
 |      ----------
 |      outfile : str or file object
 |          The file (or filename) where you want to output the html.
 |      close_file : bool, default True
 |          Whether the file has to be closed after write.
 |  
 |  to_dict(self, depth=-1, ordered=True, **kwargs)
 |      Returns a dict representation of the object.
 |  
 |  to_json(self, depth=-1, **kwargs)
 |      Returns a JSON representation of the object.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from branca.element.Element:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)


In [100]:
help(m)


Help on Map in module folium.folium object:

class Map(folium.map.LegacyMap)
 |  Create a Map with Folium and Leaflet.js
 |  
 |  Generate a base map of given width and height with either default
 |  tilesets or a custom tileset URL. The following tilesets are built-in
 |  to Folium. Pass any of the following to the "tiles" keyword:
 |  
 |      - "OpenStreetMap"
 |      - "Mapbox Bright" (Limited levels of zoom for free tiles)
 |      - "Mapbox Control Room" (Limited levels of zoom for free tiles)
 |      - "Stamen" (Terrain, Toner, and Watercolor)
 |      - "Cloudmade" (Must pass API key)
 |      - "Mapbox" (Must pass API key)
 |      - "CartoDB" (positron and dark_matter)
 |  
 |  You can pass a custom tileset to Folium by passing a Leaflet-style
 |  URL to the tiles parameter: ``http://{s}.yourtiles.com/{z}/{x}/{y}.png``
 |  
 |  Parameters
 |  ----------
 |  location: tuple or list, default None
 |      Latitude and Longitude of Map (Northing, Easting).
 |  width: pixel int or percentage string (default: '100%')
 |      Width of the map.
 |  height: pixel int or percentage string (default: '100%')
 |      Height of the map.
 |  tiles: str, default 'OpenStreetMap'
 |      Map tileset to use. Can choose from a list of built-in tiles,
 |      pass a custom URL or pass `None` to create a map without tiles.
 |  API_key: str, default None
 |      API key for Cloudmade or Mapbox tiles.
 |  max_zoom: int, default 18
 |      Maximum zoom depth for the map.
 |  zoom_start: int, default 10
 |      Initial zoom level for the map.
 |  attr: string, default None
 |      Map tile attribution; only required if passing custom tile URL.
 |  detect_retina: bool, default False
 |      If true and user is on a retina display, it will request four
 |      tiles of half the specified size and a bigger zoom level in place
 |      of one to utilize the high resolution.
 |  crs : str, default 'EPSG3857'
 |      Defines coordinate reference systems for projecting geographical points
 |      into pixel (screen) coordinates and back.
 |      You can use Leaflet's values :
 |      * EPSG3857 : The most common CRS for online maps, used by almost all
 |      free and commercial tile providers. Uses Spherical Mercator projection.
 |      Set in by default in Map's crs option.
 |      * EPSG4326 : A common CRS among GIS enthusiasts.
 |      Uses simple Equirectangular projection.
 |      * EPSG3395 : Rarely used by some commercial tile providers.
 |      Uses Elliptical Mercator projection.
 |      * Simple : A simple CRS that maps longitude and latitude into
 |      x and y directly. May be used for maps of flat surfaces
 |      (e.g. game maps). Note that the y axis should still be inverted
 |      (going from bottom to top).
 |  control_scale : bool, default False
 |      Whether to add a control scale on the map.
 |  prefer_canvas : bool, default False
 |      Forces Leaflet to use the Canvas back-end (if available) for
 |      vector layers instead of SVG. This can increase performance
 |      considerably in some cases (e.g. many thousands of circle
 |      markers on the map).
 |  no_touch : bool, default False
 |      Forces Leaflet to not use touch events even if it detects them.
 |  disable_3d : bool, default False
 |      Forces Leaflet to not use hardware-accelerated CSS 3D
 |      transforms for positioning (which may cause glitches in some
 |      rare environments) even if they're supported.
 |  
 |  Returns
 |  -------
 |  Folium LegacyMap Object
 |  
 |  Examples
 |  --------
 |  >>> map = folium.LegacyMap(location=[45.523, -122.675],
 |  ...                        width=750, height=500)
 |  >>> map = folium.LegacyMap(location=[45.523, -122.675],
 |                             tiles='Mapbox Control Room')
 |  >>> map = folium.LegacyMap(location=(45.523, -122.675), max_zoom=20,
 |                             tiles='Cloudmade', API_key='YourKey')
 |  >>> map = folium.LegacyMap(
 |  ...    location=[45.523, -122.675],
 |  ...    zoom_start=2,
 |  ...    tiles='http://{s}.tiles.mapbox.com/v3/mapbox.control-room/{z}/{x}/{y}.png',
 |  ...    attr='Mapbox attribution'
 |  ...)
 |  
 |  Method resolution order:
 |      Map
 |      folium.map.LegacyMap
 |      branca.element.MacroElement
 |      branca.element.Element
 |      __builtin__.object
 |  
 |  Methods defined here:
 |  
 |  choropleth(self, geo_data, data=None, columns=None, key_on=None, threshold_scale=None, fill_color='blue', fill_opacity=0.6, line_color='black', line_weight=1, line_opacity=1, name=None, legend_name='', topojson=None, reset=False, smooth_factor=None, highlight=None)
 |      Apply a GeoJSON overlay to the map.
 |      
 |      Plot a GeoJSON overlay on the base map. There is no requirement
 |      to bind data (passing just a GeoJSON plots a single-color overlay),
 |      but there is a data binding option to map your columnar data to
 |      different feature objects with a color scale.
 |      
 |      If data is passed as a Pandas DataFrame, the "columns" and "key-on"
 |      keywords must be included, the first to indicate which DataFrame
 |      columns to use, the second to indicate the layer in the GeoJSON
 |      on which to key the data. The 'columns' keyword does not need to be
 |      passed for a Pandas series.
 |      
 |      Colors are generated from color brewer (http://colorbrewer2.org/)
 |      sequential palettes on a D3 threshold scale. The scale defaults to the
 |      following quantiles: [0, 0.5, 0.75, 0.85, 0.9]. A custom scale can be
 |      passed to `threshold_scale` of length <=6, in order to match the
 |      color brewer range.
 |      
 |      TopoJSONs can be passed as "geo_data", but the "topojson" keyword must
 |      also be passed with the reference to the topojson objects to convert.
 |      See the topojson.feature method in the TopoJSON API reference:
 |      https://github.com/topojson/topojson/wiki/API-Reference
 |      
 |      
 |      Parameters
 |      ----------
 |      geo_data: string/object
 |          URL, file path, or data (json, dict, geopandas, etc) to your GeoJSON geometries
 |      data: Pandas DataFrame or Series, default None
 |          Data to bind to the GeoJSON.
 |      columns: dict or tuple, default None
 |          If the data is a Pandas DataFrame, the columns of data to be bound.
 |          Must pass column 1 as the key, and column 2 the values.
 |      key_on: string, default None
 |          Variable in the GeoJSON file to bind the data to. Must always
 |          start with 'feature' and be in JavaScript objection notation.
 |          Ex: 'feature.id' or 'feature.properties.statename'.
 |      threshold_scale: list, default None
 |          Data range for D3 threshold scale. Defaults to the following range
 |          of quantiles: [0, 0.5, 0.75, 0.85, 0.9], rounded to the nearest
 |          order-of-magnitude integer. Ex: 270 rounds to 200, 5600 to 6000.
 |      fill_color: string, default 'blue'
 |          Area fill color. Can pass a hex code, color name, or if you are
 |          binding data, one of the following color brewer palettes:
 |          'BuGn', 'BuPu', 'GnBu', 'OrRd', 'PuBu', 'PuBuGn', 'PuRd', 'RdPu',
 |          'YlGn', 'YlGnBu', 'YlOrBr', and 'YlOrRd'.
 |      fill_opacity: float, default 0.6
 |          Area fill opacity, range 0-1.
 |      line_color: string, default 'black'
 |          GeoJSON geopath line color.
 |      line_weight: int, default 1
 |          GeoJSON geopath line weight.
 |      line_opacity: float, default 1
 |          GeoJSON geopath line opacity, range 0-1.
 |      legend_name: string, default empty string
 |          Title for data legend.
 |      topojson: string, default None
 |          If using a TopoJSON, passing "objects.yourfeature" to the topojson
 |          keyword argument will enable conversion to GeoJSON.
 |      reset: boolean, default False
 |          Remove all current geoJSON layers, start with new layer
 |      smooth_factor: float, default None
 |          How much to simplify the polyline on each zoom level. More means
 |          better performance and smoother look, and less means more accurate
 |          representation. Leaflet defaults to 1.0.
 |      highlight: boolean, default False
 |          Enable highlight functionality when hovering over a GeoJSON area.
 |      
 |      Returns
 |      -------
 |      GeoJSON data layer in obj.template_vars
 |      
 |      Examples
 |      --------
 |      >>> m.choropleth(geo_data='us-states.json', line_color='blue',
 |      ...              line_weight=3)
 |      >>> m.choropleth(geo_data='geo.json', data=df,
 |      ...              columns=['Data 1', 'Data 2'],
 |      ...              key_on='feature.properties.myvalue',
 |      ...              fill_color='PuBu',
 |      ...              threshold_scale=[0, 20, 30, 40, 50, 60])
 |      >>> m.choropleth(geo_data='countries.json',
 |      ...              topojson='objects.countries')
 |      >>> m.choropleth(geo_data='geo.json', data=df,
 |      ...              columns=['Data 1', 'Data 2'],
 |      ...              key_on='feature.properties.myvalue',
 |      ...              fill_color='PuBu',
 |      ...              threshold_scale=[0, 20, 30, 40, 50, 60],
 |      ...              highlight=True)
 |  
 |  fit_bounds(self, bounds, padding_top_left=None, padding_bottom_right=None, padding=None, max_zoom=None)
 |      Fit the map to contain a bounding box with the
 |      maximum zoom level possible.
 |      
 |      Parameters
 |      ----------
 |      bounds: list of (latitude, longitude) points
 |          Bounding box specified as two points [southwest, northeast]
 |      padding_top_left: (x, y) point, default None
 |          Padding in the top left corner. Useful if some elements in
 |          the corner, such as controls, might obscure objects you're zooming
 |          to.
 |      padding_bottom_right: (x, y) point, default None
 |          Padding in the bottom right corner.
 |      padding: (x, y) point, default None
 |          Equivalent to setting both top left and bottom right padding to
 |          the same value.
 |      max_zoom: int, default None
 |          Maximum zoom to be used.
 |      
 |      Examples
 |      --------
 |      >>> map.fit_bounds([[52.193636, -2.221575], [52.636878, -1.139759]])
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from folium.map.LegacyMap:
 |  
 |  __init__(self, location=None, width='100%', height='100%', left='0%', top='0%', position='relative', tiles='OpenStreetMap', API_key=None, max_zoom=18, min_zoom=1, zoom_start=10, world_copy_jump=False, no_wrap=False, attr=None, min_lat=-90, max_lat=90, min_lon=-180, max_lon=180, max_bounds=False, detect_retina=False, crs='EPSG3857', control_scale=False, prefer_canvas=False, no_touch=False, disable_3d=False, subdomains='abc', png_enabled=False)
 |  
 |  add_tile_layer(self, tiles='OpenStreetMap', name=None, API_key=None, max_zoom=18, min_zoom=1, attr=None, active=False, detect_retina=False, no_wrap=False, subdomains='abc', **kwargs)
 |      Add a tile layer to the map. See TileLayer for options.
 |  
 |  render(self, **kwargs)
 |      Renders the HTML representation of the element.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from branca.element.Element:
 |  
 |  add_child(self, child, name=None, index=None)
 |      Add a child.
 |  
 |  add_children(self, child, name=None, index=None)
 |      Add a child.
 |  
 |  add_to(self, parent, name=None, index=None)
 |      Add element to a parent.
 |  
 |  get_bounds(self)
 |      Computes the bounds of the object and all it's children
 |      in the form [[lat_min, lon_min], [lat_max, lon_max]].
 |  
 |  get_name(self)
 |      Returns a string representation of the object.
 |      This string has to be unique and to be a python and
 |      javascript-compatible
 |      variable name.
 |  
 |  get_root(self)
 |      Returns the root of the elements tree.
 |  
 |  save(self, outfile, close_file=True, **kwargs)
 |      Saves an Element into a file.
 |      
 |      Parameters
 |      ----------
 |      outfile : str or file object
 |          The file (or filename) where you want to output the html.
 |      close_file : bool, default True
 |          Whether the file has to be closed after write.
 |  
 |  to_dict(self, depth=-1, ordered=True, **kwargs)
 |      Returns a dict representation of the object.
 |  
 |  to_json(self, depth=-1, **kwargs)
 |      Returns a JSON representation of the object.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from branca.element.Element:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)


In [101]:
m.to_dict()


Out[101]:
OrderedDict([('name', 'Map'),
             ('id', 'e23239bf25fe4c978b207a9fe876c64f'),
             ('children',
              OrderedDict([('cartodbpositron',
                            OrderedDict([('name', 'TileLayer'),
                                         ('id',
                                          '57d1444e0dad4180b8aaf4af5e68ee08'),
                                         ('children', OrderedDict())])),
                           ('regiones_censales',
                            OrderedDict([('name', 'GeoJson'),
                                         ('id',
                                          '4f02efbd265d4dcd9db87fe6850c1ad8'),
                                         ('children', OrderedDict())]))]))])

In [104]:
data_censo.iloc[[0], :]


Out[104]:
OBJECTID CUSEC CUMUN CSEC CDIS CMUN CPRO CCA CUDIS OBS ... CNUT2 CNUT3 CLAU2 NPRO NCA NMUN Shape_Leng Shape_area Shape_len geometry
0 5155 0807301001 08073 001 01 073 08 09 0807301 ... 1 1 08073 Barcelona Catalua Cornell de Llobregat 1352.569111 92188.616635 1352.569111 POLYGON ((2.07086332857145 41.35740405853809, ...

1 rows × 22 columns


In [183]:
m = folium.Map([41.37, 2.1], tiles='cartodbpositron', zoom_start=13)


n_splits = 10
par_splits = {'n_splits': n_splits, 'limits': (0, 1),
              'open_limits': False, 'reverse': False}
splitter = Splitters('equispaced_splitters', par_splits,
                     ranges=list(range(n_splits)))
colors = sns.color_palette('RdYlGn', n_splits)


def create_function_style(features):
    style_function = lambda x: {'fillColor': matplotlib.colors.rgb2hex(colors[splitter(features)]),
                                'fillOpacity': 0.4,
                                'color': 'black',
                                'weight': 0.5,
                                'opacity': 1}
    return style_function


highlight_function = lambda x: {'weight': 1.5,
                                'fillOpacity': 0.75}

for i in range(len(data_censo)):
    style_function = create_function_style(pro_ind.iloc[i, :]['Pro_ind'])
    geo_cens = folium.folium.GeoJson(data_censo.iloc[[i], :],
                                     style_function=style_function,
                                     highlight_function=highlight_function,
                                     overlay=True,
                                     control=False)
    geo_cens.add_child(folium.features.Popup(data_censo.iloc[i, :]['CUSEC']))
    geo_cens.add_to(m, data_censo.iloc[i, :]['CUSEC'])
m


Out[183]:

In [178]:
matplotlib.colors.rgb2hex(colors[0])


Out[178]:
u'#d22b27'

In [161]:
sns.palplot(colors)



In [140]:
import seaborn as sns
colors = sns.color_palette("RdBu_r", 7)
colors[0]


Out[140]:
(0.16339870177063293, 0.4449827098378949, 0.69750097919912901)

In [ ]:
def create_abs_splits(values, extremes):
    extremes[0], extremes[-1]

In [141]:
np.linspace(0, 1, 11)


Out[141]:
array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9,  1. ])

In [ ]:


In [ ]:


In [ ]: