stembureau-meting/jupyter/stembureau_data.ipynb
2022-05-09 18:30:16 +02:00

1.9 MiB
Raw Blame History

None <html lang="en"> <head> gitea_input3204818494 </head>

Data gemeenteraadsverkiezingen 2022 Nederland

Dit notebook is voor het verwerken van de data van de gemeenteraadsverkiezingen van 2022. Er zal hier stap voor stap door de data gelopen worden om het proces reproduceerbaar te maken voor latere verkiezingen. De eerste stap was de data ophalen van de bronnen, zowel de overheid als waar is mijn stemlokaal (voor geografische data van de stemlokalen). De bronnen gebruikt voor de data zijn voor de verkiezingen van 2022 is als volgt:

De eerste stap die we moeten maken is de data importeren voor de analyse, daarna kunnen we kijken hoe goed de data is, hoe we het aan kunnen vullen, en wat er mee te doen. De makkelijkste structuur die we vonden was het geojson bestand van open state en de Volkskrant, daar staan alle stemlokalen al in een lijst, en we hebben een makkelijk framework om het te importeren; geopandas. We laden deze dan ook als eerste in.

In [72]:
import pandas as pd
import geopandas as gpd

crs = {'init':'EPSG:4326'}
df_geojson = gpd.read_file(r'../data/2022gr.geo.json', crs=crs)
/home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/fiona/collection.py:208: FeatureWarning: Empty field name at index 928
  self._schema = self.session.get_schema()
/home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/geodataframe.py:600: UserWarning: Empty field name at index 928
  for feature in features_lst:

We importeren nu de gemeente shapefile kaart van het CBS, om de overlay van onze stemlokalen eroverheen te kunnen doen.

In [73]:
nl_map = gpd.read_file(r'../data/shape/Netherlands_shapefile/gemeente_2021_v1.shp')
nl_map.to_crs(epsg=4326).plot()
Out[73]:
<AxesSubplot:>
No description has been provided for this image
In [74]:
print(nl_map)
    GM_CODE            GM_NAAM  H2O       OAD      STED  BEV_DICHTH  AANT_INW  \
0    GM0034             Almere   JA -99999999 -99999999   -99999999 -99999999   
1    GM0050           Zeewolde   JA -99999999 -99999999   -99999999 -99999999   
2    GM0060            Ameland   JA -99999999 -99999999   -99999999 -99999999   
3    GM0072          Harlingen   JA -99999999 -99999999   -99999999 -99999999   
4    GM0088    Schiermonnikoog   JA -99999999 -99999999   -99999999 -99999999   
..      ...                ...  ...       ...       ...         ...       ...   
430  GM1966       Het Hogeland  NEE       414         5          99     47834   
431  GM1969     Westerkwartier  NEE       476         5         176     63678   
432  GM1970  Noardeast-Fryslân  NEE       463         5         120     45481   
433  GM1978        Molenlanden  NEE       393         5         243     44130   
434  GM1979          Eemsdelta  NEE       692         4         170     45587   

     AANT_MAN  AANT_VROUW  P_00_14_JR  ...  P_TURKIJE  P_OVER_NW   OPP_TOT  \
0   -99999999   -99999999   -99999999  ...  -99999999  -99999999 -99999999   
1   -99999999   -99999999   -99999999  ...  -99999999  -99999999 -99999999   
2   -99999999   -99999999   -99999999  ...  -99999999  -99999999 -99999999   
3   -99999999   -99999999   -99999999  ...  -99999999  -99999999 -99999999   
4   -99999999   -99999999   -99999999  ...  -99999999  -99999999 -99999999   
..        ...         ...         ...  ...        ...        ...       ...   
430     24052       23782          15  ...          0          3     90308   
431     32034       31644          17  ...          0          3     36887   
432     22879       22602          17  ...          0          2     51645   
433     22317       21813          18  ...          0          2     19158   
434     22841       22746          14  ...          2          5     36407   

     OPP_LAND  OPP_WATER  JRSTATCODE  JAAR     Shape_Leng    Shape_Area  \
0   -99999999  -99999999  2021GM0034  2021  122665.358635  1.095623e+08   
1   -99999999  -99999999  2021GM0050  2021   83290.773617  1.633050e+07   
2   -99999999  -99999999  2021GM0060  2021  156406.894023  2.085914e+08   
3   -99999999  -99999999  2021GM0072  2021  104274.683035  3.618323e+08   
4   -99999999  -99999999  2021GM0088  2021  152568.858991  1.624101e+08   
..        ...        ...         ...   ...            ...           ...   
430     48249      42059  2021GM1966  2021  321301.166576  4.875998e+08   
431     36269        618  2021GM1969  2021   99030.762281  3.688457e+08   
432     37783      13862  2021GM1970  2021  238426.959926  3.837930e+08   
433     18173        986  2021GM1978  2021   88570.376691  1.915841e+08   
434     26789       9618  2021GM1979  2021  173966.493452  2.727771e+08   

                                              geometry  
0    MULTIPOLYGON (((150213.998 479503.726, 150087....  
1    MULTIPOLYGON (((170588.413 486792.192, 170570....  
2    POLYGON ((196000.000 610000.000, 196000.000 60...  
3    MULTIPOLYGON (((158392.775 580357.500, 158387....  
4    POLYGON ((219000.000 616567.418, 219000.000 61...  
..                                                 ...  
430  MULTIPOLYGON (((217037.735 601967.991, 217043....  
431  POLYGON ((215186.661 595044.495, 215190.788 59...  
432  MULTIPOLYGON (((207769.575 603284.528, 207773....  
433  POLYGON ((123569.533 440132.167, 123576.153 44...  
434  MULTIPOLYGON (((269190.000 594253.046, 269190....  

[435 rows x 38 columns]
In [75]:
import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize = (10,10))
nl_map.to_crs(epsg=4326).plot(ax=ax, color='lightgrey')
df_geojson.plot(ax=ax)
Out[75]:
<AxesSubplot:>
No description has been provided for this image

We hebben hier een probleem dat sommige punten de coördinaten 0,0 hebben, dit is niet iets wat we willen weergeven. Laten we eerst kijken waarom dit het geval is in de data voordat we het er helemaal uithalen.

In [76]:
for index, row in df_geojson.iterrows():
    if (row.geometry.centroid.x == 0.00000):
        print(row)
Stembureau                                     32
Adres                                            
Locatie                                      SB32
description        Stembureau Mobiel Stembureau 1
Geldige stemmen                                99
                                ...              
één-Ermelo                                    NaN
gmcode                                     GM0109
election                         GR2022_Coevorden
electionName          Gemeenteraad Coevorden 2022
geometry                              POINT (0 0)
Name: 2520, Length: 973, dtype: object
Stembureau                                     33
Adres                                            
Locatie                                      SB33
description        Stembureau Mobiel Stembureau 2
Geldige stemmen                               115
                                ...              
één-Ermelo                                    NaN
gmcode                                     GM0109
election                         GR2022_Coevorden
electionName          Gemeenteraad Coevorden 2022
geometry                              POINT (0 0)
Name: 2521, Length: 973, dtype: object
Stembureau                                   157
Adres                                           
Locatie                                    SB157
description        Stembureau Stembureau Stembus
Geldige stemmen                               72
                               ...              
één-Ermelo                                   NaN
gmcode                                    GM0150
election                         GR2022_Deventer
electionName          Gemeenteraad Deventer 2022
geometry                             POINT (0 0)
Name: 2918, Length: 973, dtype: object
Stembureau                                                       171
Adres                                                               
Locatie                                                        SB171
description        Stembureau Stembureau Stembureau op locatie al...
Geldige stemmen                                                  174
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0772
election                                            GR2022_Eindhoven
electionName                             Gemeenteraad Eindhoven 2022
geometry                                                 POINT (0 0)
Name: 3579, Length: 973, dtype: object
Stembureau                                                       172
Adres                                                               
Locatie                                                        SB172
description        Stembureau Stembureau Stembureau op locatie al...
Geldige stemmen                                                   66
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0772
election                                            GR2022_Eindhoven
electionName                             Gemeenteraad Eindhoven 2022
geometry                                                 POINT (0 0)
Name: 3580, Length: 973, dtype: object
Stembureau                                                       173
Adres                                                               
Locatie                                                        SB173
description        Stembureau Stembureau Stembureau op locatie al...
Geldige stemmen                                                  162
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0772
election                                            GR2022_Eindhoven
electionName                             Gemeenteraad Eindhoven 2022
geometry                                                 POINT (0 0)
Name: 3581, Length: 973, dtype: object
Stembureau                                                       174
Adres                                                               
Locatie                                                        SB174
description        Stembureau Stembureau Stembureau op locatie al...
Geldige stemmen                                                   65
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0772
election                                            GR2022_Eindhoven
electionName                             Gemeenteraad Eindhoven 2022
geometry                                                 POINT (0 0)
Name: 3582, Length: 973, dtype: object
Stembureau                                                       175
Adres                                                               
Locatie                                                        SB175
description        Stembureau Stembureau Stembureau op locatie al...
Geldige stemmen                                                  121
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0772
election                                            GR2022_Eindhoven
electionName                             Gemeenteraad Eindhoven 2022
geometry                                                 POINT (0 0)
Name: 3583, Length: 973, dtype: object
Stembureau                                                        39
Adres                                                               
Locatie                                                         SB39
description        Stembureau Mobiel stembureau met beperkte toeg...
Geldige stemmen                                                   56
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM1735
election                                         GR2022_HofvanTwente
electionName                        Gemeenteraad Hof van Twente 2022
geometry                                                 POINT (0 0)
Name: 5494, Length: 973, dtype: object
Stembureau                                                        34
Adres                                                               
Locatie                                                         SB34
description        Stembureau Stembureau Mobiel stembureau verzor...
Geldige stemmen                                                  119
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0166
election                                               GR2022_Kampen
electionName                                Gemeenteraad Kampen 2022
geometry                                                 POINT (0 0)
Name: 5784, Length: 973, dtype: object
Stembureau                                                        35
Adres                                                               
Locatie                                                         SB35
description        Stembureau Stembureau Mobiel stembureau verzor...
Geldige stemmen                                                  151
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0166
election                                               GR2022_Kampen
electionName                                Gemeenteraad Kampen 2022
geometry                                                 POINT (0 0)
Name: 5785, Length: 973, dtype: object
Stembureau                                            11
Adres                                                   
Locatie                                             SB11
description        Stembureau Mobiel stembureau Ommedijk
Geldige stemmen                                       14
                                   ...                  
één-Ermelo                                           NaN
gmcode                                            GM0547
election                               GR2022_Leiderdorp
electionName                Gemeenteraad Leiderdorp 2022
geometry                                     POINT (0 0)
Name: 6260, Length: 973, dtype: object
Stembureau                                                        12
Adres                                                               
Locatie                                                         SB12
description        Stembureau Mobiel stembureau Van Alphenstaete ...
Geldige stemmen                                                   68
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0547
election                                           GR2022_Leiderdorp
electionName                            Gemeenteraad Leiderdorp 2022
geometry                                                 POINT (0 0)
Name: 6261, Length: 973, dtype: object
Stembureau                                   70
Adres                                          
Locatie                                    SB70
description        Stembureau Mobiel stembureau
Geldige stemmen                              34
                               ...             
één-Ermelo                                  NaN
gmcode                                   GM0938
election                        GR2022_Meerssen
electionName         Gemeenteraad Meerssen 2022
geometry                            POINT (0 0)
Name: 6738, Length: 973, dtype: object
Stembureau                                   71
Adres                                          
Locatie                                    SB71
description        Stembureau Mobiel stembureau
Geldige stemmen                              43
                               ...             
één-Ermelo                                  NaN
gmcode                                   GM0938
election                        GR2022_Meerssen
electionName         Gemeenteraad Meerssen 2022
geometry                            POINT (0 0)
Name: 6739, Length: 973, dtype: object
Stembureau                                             699
Adres                                                     
Locatie                                              SB699
description        Stembureau Stembureau Mobiel stembureau
Geldige stemmen                                         59
                                    ...                   
één-Ermelo                                             NaN
gmcode                                              GM0687
election                                 GR2022_Middelburg
electionName                  Gemeenteraad Middelburg 2022
geometry                                       POINT (0 0)
Name: 6863, Length: 973, dtype: object
Stembureau                                   32
Adres                                          
Locatie                                    SB32
description         Stembureau Mobielstembureau
Geldige stemmen                              63
                               ...             
één-Ermelo                                  NaN
gmcode                                   GM1930
election                      GR2022_Nissewaard
electionName       Gemeenteraad Nissewaard 2022
geometry                            POINT (0 0)
Name: 7348, Length: 973, dtype: object
Stembureau                                   90
Adres                                          
Locatie                                    SB90
description            Stembureau Roll and Vote
Geldige stemmen                             339
                               ...             
één-Ermelo                                  NaN
gmcode                                   GM1930
election                      GR2022_Nissewaard
electionName       Gemeenteraad Nissewaard 2022
geometry                            POINT (0 0)
Name: 7364, Length: 973, dtype: object
Stembureau                                   19
Adres                                          
Locatie                                    SB19
description        Stembureau Mobiel stembureau
Geldige stemmen                              77
                               ...             
één-Ermelo                                  NaN
gmcode                                   GM0086
election                      GR2022_Opsterland
electionName       Gemeenteraad Opsterland 2022
geometry                            POINT (0 0)
Name: 7857, Length: 973, dtype: object
Stembureau                                                    1428
Adres                                                             
Locatie                                                     SB1428
description        Stembureau Drive-thru parkeerplaats Rusheuvel 1
Geldige stemmen                                                163
                                        ...                       
één-Ermelo                                                     NaN
gmcode                                                      GM0828
election                                                GR2022_Oss
electionName                                 Gemeenteraad Oss 2022
geometry                                               POINT (0 0)
Name: 7912, Length: 973, dtype: object
Stembureau                                                    1437
Adres                                                             
Locatie                                                     SB1437
description        Stembureau Drive-thru parkeerplaats Rusheuvel 2
Geldige stemmen                                                239
                                        ...                       
één-Ermelo                                                     NaN
gmcode                                                      GM0828
election                                                GR2022_Oss
electionName                                 Gemeenteraad Oss 2022
geometry                                               POINT (0 0)
Name: 7913, Length: 973, dtype: object
Stembureau                                                    1528
Adres                                                             
Locatie                                                     SB1528
description        Stembureau Drive-thru parkeerplaats Rusheuvel 1
Geldige stemmen                                                323
                                        ...                       
één-Ermelo                                                     NaN
gmcode                                                      GM0828
election                                                GR2022_Oss
electionName                                 Gemeenteraad Oss 2022
geometry                                               POINT (0 0)
Name: 7923, Length: 973, dtype: object
Stembureau                                                    1537
Adres                                                             
Locatie                                                     SB1537
description        Stembureau Drive-thru parkeerplaats Rusheuvel 2
Geldige stemmen                                                208
                                        ...                       
één-Ermelo                                                     NaN
gmcode                                                      GM0828
election                                                GR2022_Oss
electionName                                 Gemeenteraad Oss 2022
geometry                                               POINT (0 0)
Name: 7924, Length: 973, dtype: object
Stembureau                                 1541
Adres                                          
Locatie                                  SB1541
description        Stembureau Mobiel stembureau
Geldige stemmen                             125
                               ...             
één-Ermelo                                  NaN
gmcode                                   GM0828
election                             GR2022_Oss
electionName              Gemeenteraad Oss 2022
geometry                            POINT (0 0)
Name: 7926, Length: 973, dtype: object
Stembureau                                         200
Adres                                                 
Locatie                                          SB200
description            Stembureau Mobiel stembureau Ma
Geldige stemmen                                     30
                                  ...                 
één-Ermelo                                         NaN
gmcode                                          GM1509
election                       GR2022_OudeIJsselstreek
electionName       Gemeenteraad Oude IJsselstreek 2022
geometry                                   POINT (0 0)
Name: 7958, Length: 973, dtype: object
Stembureau                                         201
Adres                                                 
Locatie                                          SB201
description            Stembureau Mobiel stembureau Di
Geldige stemmen                                     30
                                  ...                 
één-Ermelo                                         NaN
gmcode                                          GM1509
election                       GR2022_OudeIJsselstreek
electionName       Gemeenteraad Oude IJsselstreek 2022
geometry                                   POINT (0 0)
Name: 7959, Length: 973, dtype: object
Stembureau                                         202
Adres                                                 
Locatie                                          SB202
description           Stembureau Mobiel stembureau Woe
Geldige stemmen                                     44
                                  ...                 
één-Ermelo                                         NaN
gmcode                                          GM1509
election                       GR2022_OudeIJsselstreek
electionName       Gemeenteraad Oude IJsselstreek 2022
geometry                                   POINT (0 0)
Name: 7960, Length: 973, dtype: object
Stembureau                                                        30
Adres                                                               
Locatie                                                         SB30
description        Stembureau Stembureau voor de telling stembure...
Geldige stemmen                                                 2004
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM1926
election                                    GR2022_PijnackerNootdorp
electionName                    Gemeenteraad Pijnacker-Nootdorp 2022
geometry                                                 POINT (0 0)
Name: 8108, Length: 973, dtype: object
Stembureau                                                        40
Adres                                                               
Locatie                                                         SB40
description        Stembureau Stembureau voor de telling stembure...
Geldige stemmen                                                 2953
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM1926
election                                    GR2022_PijnackerNootdorp
electionName                    Gemeenteraad Pijnacker-Nootdorp 2022
geometry                                                 POINT (0 0)
Name: 8109, Length: 973, dtype: object
Stembureau                                                      990
Adres                                                              
Locatie                                                       SB990
description        Stembureau Mobiel stembureau (meerdere plaatsen)
Geldige stemmen                                                  47
                                         ...                       
één-Ermelo                                                      NaN
gmcode                                                       GM0177
election                                              GR2022_Raalte
electionName                               Gemeenteraad Raalte 2022
geometry                                                POINT (0 0)
Name: 8161, Length: 973, dtype: object
Stembureau                                                      991
Adres                                                              
Locatie                                                       SB991
description        Stembureau Mobiel stembureau (meerdere plaatsen)
Geldige stemmen                                                  70
                                         ...                       
één-Ermelo                                                      NaN
gmcode                                                       GM0177
election                                              GR2022_Raalte
electionName                               Gemeenteraad Raalte 2022
geometry                                                POINT (0 0)
Name: 8162, Length: 973, dtype: object
Stembureau                                                      992
Adres                                                              
Locatie                                                       SB992
description        Stembureau Mobiel stembureau (meerdere plaatsen)
Geldige stemmen                                                  39
                                         ...                       
één-Ermelo                                                      NaN
gmcode                                                       GM0177
election                                              GR2022_Raalte
electionName                               Gemeenteraad Raalte 2022
geometry                                                POINT (0 0)
Name: 8163, Length: 973, dtype: object
Stembureau                                           17
Adres                                                  
Locatie                                            SB17
description        Stembureau Mobiel Stembureau dinsdag
Geldige stemmen                                     115
                                   ...                 
één-Ermelo                                          NaN
gmcode                                           GM1742
election                           GR2022_RijssenHolten
electionName           Gemeenteraad Rijssen-Holten 2022
geometry                                    POINT (0 0)
Name: 8318, Length: 973, dtype: object
Stembureau                                    228
Adres                                            
Locatie                                     SB228
description        Stembureau Stembureau Drive-in
Geldige stemmen                                80
                                ...              
één-Ermelo                                    NaN
gmcode                                     GM0606
election                          GR2022_Schiedam
electionName           Gemeenteraad Schiedam 2022
geometry                              POINT (0 0)
Name: 9093, Length: 973, dtype: object
Stembureau                                           30
Adres                                                  
Locatie                                            SB30
description                Stembureau Mobiel stembureau
Geldige stemmen                                      25
                                   ...                 
één-Ermelo                                          NaN
gmcode                                           GM1676
election                       GR2022_SchouwenDuiveland
electionName       Gemeenteraad Schouwen-Duiveland 2022
geometry                                    POINT (0 0)
Name: 9151, Length: 973, dtype: object
Stembureau                                           31
Adres                                                  
Locatie                                            SB31
description                Stembureau Mobiel stembureau
Geldige stemmen                                       8
                                   ...                 
één-Ermelo                                          NaN
gmcode                                           GM1676
election                       GR2022_SchouwenDuiveland
electionName       Gemeenteraad Schouwen-Duiveland 2022
geometry                                    POINT (0 0)
Name: 9152, Length: 973, dtype: object
Stembureau                                           32
Adres                                                  
Locatie                                            SB32
description                Stembureau Mobiel stembureau
Geldige stemmen                                      24
                                   ...                 
één-Ermelo                                          NaN
gmcode                                           GM1676
election                       GR2022_SchouwenDuiveland
electionName       Gemeenteraad Schouwen-Duiveland 2022
geometry                                    POINT (0 0)
Name: 9153, Length: 973, dtype: object
Stembureau                                          76
Adres                                                 
Locatie                                           SB76
description        Stembureau Rondvaartboot Toerist VI
Geldige stemmen                                    148
                                  ...                 
één-Ermelo                                         NaN
gmcode                                          GM1900
election                         GR2022_SudwestFryslan
electionName         Gemeenteraad Súdwest-Fryslân 2022
geometry                                   POINT (0 0)
Name: 9661, Length: 973, dtype: object
Stembureau                                                        68
Adres                                                               
Locatie                                                         SB68
description        Stembureau Drive Inn (evenemententerrein Het L...
Geldige stemmen                                                  285
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0855
election                                              GR2022_Tilburg
electionName                               Gemeenteraad Tilburg 2022
geometry                                                 POINT (0 0)
Name: 9853, Length: 973, dtype: object
Stembureau                                   14
Adres                                          
Locatie                                    SB14
description        Stembureau Mobiel Stembureau
Geldige stemmen                              24
                               ...             
één-Ermelo                                  NaN
gmcode                                   GM0047
election                         GR2022_Veendam
electionName          Gemeenteraad Veendam 2022
geometry                            POINT (0 0)
Name: 10427, Length: 973, dtype: object
Stembureau                                   18
Adres                                          
Locatie                                    SB18
description        Stembureau Mobiel stembureau
Geldige stemmen                              50
                               ...             
één-Ermelo                                  NaN
gmcode                                   GM0047
election                         GR2022_Veendam
electionName          Gemeenteraad Veendam 2022
geometry                            POINT (0 0)
Name: 10431, Length: 973, dtype: object
Stembureau                                                   23
Adres                                                          
Locatie                                                    SB23
description        Stembureau Stembureau Mobiel: Wkp Zout Veere
Geldige stemmen                                              55
                                       ...                     
één-Ermelo                                                  NaN
gmcode                                                   GM0717
election                                           GR2022_Veere
electionName                            Gemeenteraad Veere 2022
geometry                                            POINT (0 0)
Name: 10497, Length: 973, dtype: object
Stembureau                                            24
Adres                                                   
Locatie                                             SB24
description        Stembureau Stembureau Mobiel: Okp Dom
Geldige stemmen                                       35
                                   ...                  
één-Ermelo                                           NaN
gmcode                                            GM0717
election                                    GR2022_Veere
electionName                     Gemeenteraad Veere 2022
geometry                                     POINT (0 0)
Name: 10498, Length: 973, dtype: object
Stembureau                                     115
Adres                                             
Locatie                                      SB115
description        Stembureau Tent Nijverheidslaan
Geldige stemmen                                258
                                ...               
één-Ermelo                                     NaN
gmcode                                      GM0861
election                          GR2022_Veldhoven
electionName           Gemeenteraad Veldhoven 2022
geometry                               POINT (0 0)
Name: 10525, Length: 973, dtype: object
Stembureau                                     116
Adres                                             
Locatie                                      SB116
description        Stembureau Tent Nijverheidslaan
Geldige stemmen                                377
                                ...               
één-Ermelo                                     NaN
gmcode                                      GM0861
election                          GR2022_Veldhoven
electionName           Gemeenteraad Veldhoven 2022
geometry                               POINT (0 0)
Name: 10526, Length: 973, dtype: object
Stembureau                                         117
Adres                                                 
Locatie                                          SB117
description        Stembureau Tent Peter Benenson park
Geldige stemmen                                    285
                                  ...                 
één-Ermelo                                         NaN
gmcode                                          GM0861
election                              GR2022_Veldhoven
electionName               Gemeenteraad Veldhoven 2022
geometry                                   POINT (0 0)
Name: 10527, Length: 973, dtype: object
Stembureau                                         118
Adres                                                 
Locatie                                          SB118
description        Stembureau Tent Peter Benenson park
Geldige stemmen                                    329
                                  ...                 
één-Ermelo                                         NaN
gmcode                                          GM0861
election                              GR2022_Veldhoven
electionName               Gemeenteraad Veldhoven 2022
geometry                                   POINT (0 0)
Name: 10528, Length: 973, dtype: object
Stembureau                                              310
Adres                                                      
Locatie                                               SB310
description        Stembureau Mobiel Bijzonder stembureau 1
Geldige stemmen                                          26
                                     ...                   
één-Ermelo                                              NaN
gmcode                                               GM0983
election                                       GR2022_Venlo
electionName                        Gemeenteraad Venlo 2022
geometry                                        POINT (0 0)
Name: 10623, Length: 973, dtype: object
Stembureau                                              311
Adres                                                      
Locatie                                               SB311
description        Stembureau Mobiel Bijzonder stembureau 2
Geldige stemmen                                          55
                                     ...                   
één-Ermelo                                              NaN
gmcode                                               GM0983
election                                       GR2022_Venlo
electionName                        Gemeenteraad Venlo 2022
geometry                                        POINT (0 0)
Name: 10624, Length: 973, dtype: object
Stembureau                                     88
Adres                                            
Locatie                                      SB88
description        Stembureau Mobiel stembureau 1
Geldige stemmen                                78
                                ...              
één-Ermelo                                    NaN
gmcode                                     GM1949
election                         GR2022_Waadhoeke
electionName          Gemeenteraad Waadhoeke 2022
geometry                              POINT (0 0)
Name: 10894, Length: 973, dtype: object
Stembureau                                     89
Adres                                            
Locatie                                      SB89
description        Stembureau Mobiel stembureau 2
Geldige stemmen                                35
                                ...              
één-Ermelo                                    NaN
gmcode                                     GM1949
election                         GR2022_Waadhoeke
electionName          Gemeenteraad Waadhoeke 2022
geometry                              POINT (0 0)
Name: 10895, Length: 973, dtype: object
Stembureau                                              31
Adres                                                     
Locatie                                               SB31
description        Stembureau Stembureau Mobiel Stembureau
Geldige stemmen                                         32
                                    ...                   
één-Ermelo                                             NaN
gmcode                                              GM0988
election                                      GR2022_Weert
electionName                       Gemeenteraad Weert 2022
geometry                                       POINT (0 0)
Name: 11032, Length: 973, dtype: object
Stembureau                                     0
Adres                                           
Locatie                                      SB0
description                         Stembureau -
Geldige stemmen                                0
                               ...              
één-Ermelo                                   NaN
gmcode                                    GM1960
election                       GR2022_WestBetuwe
electionName       Gemeenteraad West Betuwe 2022
geometry                             POINT (0 0)
Name: 11101, Length: 973, dtype: object
Stembureau                                                       132
Adres                                                               
Locatie                                                        SB132
description        Stembureau Stembureau IJsselhallen drive thoug...
Geldige stemmen                                                   52
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0193
election                                               GR2022_Zwolle
electionName                                Gemeenteraad Zwolle 2022
geometry                                                 POINT (0 0)
Name: 12038, Length: 973, dtype: object
Stembureau                                                       133
Adres                                                               
Locatie                                                        SB133
description        Stembureau Stembureau IJsselhallen drive throu...
Geldige stemmen                                                   48
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0193
election                                               GR2022_Zwolle
electionName                                Gemeenteraad Zwolle 2022
geometry                                                 POINT (0 0)
Name: 12039, Length: 973, dtype: object
Stembureau                                                       232
Adres                                                               
Locatie                                                        SB232
description        Stembureau Stembureau IJsselhallen drive thoug...
Geldige stemmen                                                  113
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0193
election                                               GR2022_Zwolle
electionName                                Gemeenteraad Zwolle 2022
geometry                                                 POINT (0 0)
Name: 12053, Length: 973, dtype: object
Stembureau                                                       233
Adres                                                               
Locatie                                                        SB233
description        Stembureau Stembureau IJsselhallen drive throu...
Geldige stemmen                                                   73
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0193
election                                               GR2022_Zwolle
electionName                                Gemeenteraad Zwolle 2022
geometry                                                 POINT (0 0)
Name: 12054, Length: 973, dtype: object
Stembureau                                               358
Adres                                                       
Locatie                                                SB358
description        Stembureau Stembureau Mobiel stembureau 1
Geldige stemmen                                           70
                                     ...                    
één-Ermelo                                               NaN
gmcode                                                GM0193
election                                       GR2022_Zwolle
electionName                        Gemeenteraad Zwolle 2022
geometry                                         POINT (0 0)
Name: 12118, Length: 973, dtype: object
Stembureau                                               359
Adres                                                       
Locatie                                                SB359
description        Stembureau Stembureau Mobiel stembureau 2
Geldige stemmen                                          169
                                     ...                    
één-Ermelo                                               NaN
gmcode                                                GM0193
election                                       GR2022_Zwolle
electionName                        Gemeenteraad Zwolle 2022
geometry                                         POINT (0 0)
Name: 12119, Length: 973, dtype: object
Stembureau                                               360
Adres                                                       
Locatie                                                SB360
description        Stembureau Stembureau Mobiel stembureau 3
Geldige stemmen                                           89
                                     ...                    
één-Ermelo                                               NaN
gmcode                                                GM0193
election                                       GR2022_Zwolle
electionName                        Gemeenteraad Zwolle 2022
geometry                                         POINT (0 0)
Name: 12120, Length: 973, dtype: object
Stembureau                                               361
Adres                                                       
Locatie                                                SB361
description        Stembureau Stembureau Mobiel stembureau 4
Geldige stemmen                                           36
                                     ...                    
één-Ermelo                                               NaN
gmcode                                                GM0193
election                                       GR2022_Zwolle
electionName                        Gemeenteraad Zwolle 2022
geometry                                         POINT (0 0)
Name: 12121, Length: 973, dtype: object
Stembureau                                                       114
Adres                                                               
Locatie                                                        SB114
description        Stembureau Stembureau Mobiel stembureau (beper...
Geldige stemmen                                                  109
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0796
election                                       GR2022_sHertogenbosch
electionName                      Gemeenteraad 's-Hertogenbosch 2022
geometry                                                 POINT (0 0)
Name: 12504, Length: 973, dtype: object
Stembureau                                                       115
Adres                                                               
Locatie                                                        SB115
description        Stembureau Stembureau Mobiel Stembureau (beper...
Geldige stemmen                                                   80
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0796
election                                       GR2022_sHertogenbosch
electionName                      Gemeenteraad 's-Hertogenbosch 2022
geometry                                                 POINT (0 0)
Name: 12505, Length: 973, dtype: object
Stembureau                                                       116
Adres                                                               
Locatie                                                        SB116
description        Stembureau Stembureau Mobiel Stembureau (beper...
Geldige stemmen                                                  119
                                         ...                        
één-Ermelo                                                       NaN
gmcode                                                        GM0796
election                                       GR2022_sHertogenbosch
electionName                      Gemeenteraad 's-Hertogenbosch 2022
geometry                                                 POINT (0 0)
Name: 12506, Length: 973, dtype: object

Het zijn dus duidelijk allemaal mobiele stemlokalen, die kunnen we in een aparte dataset houden voor later, voor nu zijn ze onbelangrijk voor de kaartweergave, laten we de dataset dus opsplitsen in drie dataframes, de originele, één frame zonder de mobiele stemlokalen, en de mobiele stemlokalen alleen.

In [77]:
#de waarschuwing over de projectie die niet klopt kan genegeerd worden, we zoeken naar data die x = 0 is, de projectie gaat geen effect hebben op die data in Nederland
#filter de data en print welke waardes 0 hebben op x
mobiel_mask = df_geojson['geometry'].centroid.x == 0
i = 0
for item in mobiel_mask:
    if item:
        print(i)
    i = i + 1
/tmp/ipykernel_112022/291552514.py:3: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.

  mobiel_mask = df_geojson['geometry'].centroid.x == 0
2520
2521
2918
3579
3580
3581
3582
3583
5494
5784
5785
6260
6261
6738
6739
6863
7348
7364
7857
7912
7913
7923
7924
7926
7958
7959
7960
8108
8109
8161
8162
8163
8318
9093
9151
9152
9153
9661
9853
10427
10431
10497
10498
10525
10526
10527
10528
10623
10624
10894
10895
11032
11101
12038
12039
12053
12054
12118
12119
12120
12121
12504
12505
12506
In [78]:
df_geojson_clean = df_geojson[~mobiel_mask]
df_geojson_mobiel = df_geojson[mobiel_mask]
print(df_geojson_clean)
       Stembureau   Adres Locatie  \
0               1  9461BH     SB1   
1               2  9461DA     SB2   
2               3  9461JA     SB3   
3               4  9451KD     SB4   
4               6  9454PL     SB6   
...           ...     ...     ...   
12591         703  5391AR   SB703   
12592         705  5391AR   SB705   
12593         750  5382KE   SB750   
12594         751  5382KE   SB751   
12595         752  5283KE   SB752   

                                             description  Geldige stemmen  \
0      Stembureau Gemeentehuis Gieten (postcode: 9461...              784   
1              Stembureau OBS Gieten (postcode: 9461 DA)              562   
2      Stembureau Zorgcentrum Dekelhem (postcode: 946...              566   
3      Stembureau Ontmoetingscentrum Boerhorn Rolde (...             1495   
4      Stembureau Dropshuis de Eekhof (postcode: 9454...              347   
...                                                  ...              ...   
12591  Stembureau Stembureau Gemeenschapshuis de Meen...              268   
12592  Stembureau Stembureau Gemeenschapshuis De Meen...              398   
12593  Stembureau Stembureau Gemeenschapshuis 't Zijl...              663   
12594  Stembureau Stembureau Gemeenschapshuis 't Zijl...              170   
12595  Stembureau Stembureau Gemeenschapshuis 't Zijl...              222   

       Opgeroepen  Ongeldig  Blanco  Geldige stempassen  \
0            2780         3       3                 700   
1            1396         0       0                 518   
2            1409         2       2                 516   
3            2209         2       4                1335   
4             477         0       2                 298   
...           ...       ...     ...                 ...   
12591           0         0       1                 237   
12592           0         1       0                 359   
12593        2321         2       0                 552   
12594           0         0       0                 151   
12595           0         0       0                 193   

       Geldige volmachtbewijzen  ...  Partij voor Logisch Beleid (PvLB)  \
0                            90  ...                                NaN   
1                            44  ...                                NaN   
2                            54  ...                                NaN   
3                           166  ...                                NaN   
4                            51  ...                                NaN   
...                         ...  ...                                ...   
12591                        32  ...                                NaN   
12592                        40  ...                                NaN   
12593                       113  ...                                NaN   
12594                        19  ...                                NaN   
12595                        29  ...                                NaN   

       Socialisten 010  Jong Rotterdam  VOOR Den Bosch Joep Gersjes  \
0                  NaN             NaN                          NaN   
1                  NaN             NaN                          NaN   
2                  NaN             NaN                          NaN   
3                  NaN             NaN                          NaN   
4                  NaN             NaN                          NaN   
...                ...             ...                          ...   
12591              NaN             NaN                          0.0   
12592              NaN             NaN                          2.0   
12593              NaN             NaN                          5.0   
12594              NaN             NaN                          1.0   
12595              NaN             NaN                          0.0   

       Zorg Voor Gorkum  één-Ermelo  gmcode               election  \
0                   NaN         NaN  GM1680       GR2022_AaenHunze   
1                   NaN         NaN  GM1680       GR2022_AaenHunze   
2                   NaN         NaN  GM1680       GR2022_AaenHunze   
3                   NaN         NaN  GM1680       GR2022_AaenHunze   
4                   NaN         NaN  GM1680       GR2022_AaenHunze   
...                 ...         ...     ...                    ...   
12591               NaN         NaN  GM0796  GR2022_sHertogenbosch   
12592               NaN         NaN  GM0796  GR2022_sHertogenbosch   
12593               NaN         NaN  GM0796  GR2022_sHertogenbosch   
12594               NaN         NaN  GM0796  GR2022_sHertogenbosch   
12595               NaN         NaN  GM0796  GR2022_sHertogenbosch   

                             electionName                  geometry  
0           Gemeenteraad Aa en Hunze 2022  POINT (6.75899 53.00524)  
1           Gemeenteraad Aa en Hunze 2022  POINT (6.75990 52.99975)  
2           Gemeenteraad Aa en Hunze 2022  POINT (6.76600 53.00494)  
3           Gemeenteraad Aa en Hunze 2022  POINT (6.64736 52.98281)  
4           Gemeenteraad Aa en Hunze 2022  POINT (6.60459 52.95269)  
...                                   ...                       ...  
12591  Gemeenteraad 's-Hertogenbosch 2022  POINT (5.43290 51.72810)  
12592  Gemeenteraad 's-Hertogenbosch 2022  POINT (5.43290 51.72810)  
12593  Gemeenteraad 's-Hertogenbosch 2022  POINT (5.45919 51.70595)  
12594  Gemeenteraad 's-Hertogenbosch 2022  POINT (5.45919 51.70595)  
12595  Gemeenteraad 's-Hertogenbosch 2022  POINT (5.45919 51.70595)  

[12532 rows x 973 columns]
In [79]:
#let's also check if none fell through the cracks, it might be some mobile polls did actually have a location posted erroneously.
#mobiel_mask_name = df_geojson_clean['description'].str.contains('Mobiel')
#df_geojson_clean = df_geojson_clean[~mobiel_mask_name]
#df_geojson_clean
In [86]:
df_wims = pd.read_csv(r'../data/wims-3.csv')
df_wims
Out[86]:
_id Gemeente CBS gemeentecode Nummer stembureau Naam stembureau Gebruiksdoel van het gebouw Website locatie Wijknaam CBS wijknummer Buurtnaam ... Kieskring ID Hoofdstembureau Tellocatie Contactgegevens gemeente Verkiezingswebsite gemeente Verkiezingen ID UUID Unnamed: 39 Unnamed: 40
0 1 Valkenswaard GM0858 1 Zorgcentrum Kempenhof gezondheidszorgfunctie https://www.valkenhof.nl/ NaN NaN NaN ... Valkenswaard Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 3a612b2151fa4ab491b9e331355e6258 NaN NaN
1 2 Valkenswaard GM0858 2 Buurtgebouw De Horizon bijeenkomstfunctie NaN NaN NaN NaN ... Valkenswaard Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 9a01d765af0a467ea37f08d92db114ba NaN NaN
2 3 Valkenswaard GM0858 3 Speeltuin Geenhoven bijeenkomstfunctie NaN NaN NaN NaN ... Valkenswaard Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 fc5869d33fbc4b06be659149fa615f4c NaN NaN
3 4 Valkenswaard GM0858 4 Ontmoetingscentrum De zoete inval bijeenkomstfunctie NaN NaN NaN NaN ... Valkenswaard Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 4427cc0b39e040ba8f75c333f19d66f0 NaN NaN
4 5 Valkenswaard GM0858 5 Gymnastiekzaal 't Gegraaf sportfunctie NaN NaN NaN NaN ... Valkenswaard Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 a893bb9add324ce29769f1c39afcc48d NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
9270 38745 Gennep GM0907 4 Het Hökske bijeenkomstfunctie NaN NaN NaN NaN ... Gennep Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 f744546cd6894e5e9a4db4bbfd81b4ee NaN NaN
9271 38746 Gennep GM0907 5 Buurthuis VanOns bijeenkomstfunctie NaN NaN NaN NaN ... Gennep Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 1270081b1dc74cd7bea0f45973650408 NaN NaN
9272 38747 Gennep GM0907 6 't Trefpunt bijeenkomstfunctie NaN NaN NaN NaN ... Gennep Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 447c7742604345139e41def4cf1e4d3c NaN NaN
9273 38748 Gennep GM0907 8 De Uitkomst bijeenkomstfunctie NaN NaN NaN NaN ... Gennep Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 049cfd258c174bc49abf17883396d083 NaN NaN
9274 38749 Gennep GM0907 1 Zaal Buurman woonfunctie,bijeenkomstfunctie NaN NaN NaN NaN ... Gennep Gennep NaN Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 1e8cbe96e72c4c6ba6303f47bec8cdb5 NaN NaN

9275 rows × 41 columns

In [87]:
gdf_wims = gpd.GeoDataFrame(
    df_wims, geometry=gpd.points_from_xy(df_wims.Longitude, df_wims.Latitude)).set_crs(epsg=4326, inplace=True)

gdf_wims
Out[87]:
_id Gemeente CBS gemeentecode Nummer stembureau Naam stembureau Gebruiksdoel van het gebouw Website locatie Wijknaam CBS wijknummer Buurtnaam ... Hoofdstembureau Tellocatie Contactgegevens gemeente Verkiezingswebsite gemeente Verkiezingen ID UUID Unnamed: 39 Unnamed: 40 geometry
0 1 Valkenswaard GM0858 1 Zorgcentrum Kempenhof gezondheidszorgfunctie https://www.valkenhof.nl/ NaN NaN NaN ... Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 3a612b2151fa4ab491b9e331355e6258 NaN NaN POINT (5.45515 51.34711)
1 2 Valkenswaard GM0858 2 Buurtgebouw De Horizon bijeenkomstfunctie NaN NaN NaN NaN ... Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 9a01d765af0a467ea37f08d92db114ba NaN NaN POINT (5.45137 51.34955)
2 3 Valkenswaard GM0858 3 Speeltuin Geenhoven bijeenkomstfunctie NaN NaN NaN NaN ... Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 fc5869d33fbc4b06be659149fa615f4c NaN NaN POINT (5.44827 51.35702)
3 4 Valkenswaard GM0858 4 Ontmoetingscentrum De zoete inval bijeenkomstfunctie NaN NaN NaN NaN ... Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 4427cc0b39e040ba8f75c333f19d66f0 NaN NaN POINT (5.44871 51.36022)
4 5 Valkenswaard GM0858 5 Gymnastiekzaal 't Gegraaf sportfunctie NaN NaN NaN NaN ... Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 a893bb9add324ce29769f1c39afcc48d NaN NaN POINT (5.45331 51.36514)
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
9270 38745 Gennep GM0907 4 Het Hökske bijeenkomstfunctie NaN NaN NaN NaN ... Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 f744546cd6894e5e9a4db4bbfd81b4ee NaN NaN POINT (5.98266 51.69726)
9271 38746 Gennep GM0907 5 Buurthuis VanOns bijeenkomstfunctie NaN NaN NaN NaN ... Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 1270081b1dc74cd7bea0f45973650408 NaN NaN POINT (5.98127 51.69000)
9272 38747 Gennep GM0907 6 't Trefpunt bijeenkomstfunctie NaN NaN NaN NaN ... Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 447c7742604345139e41def4cf1e4d3c NaN NaN POINT (5.95118 51.72591)
9273 38748 Gennep GM0907 8 De Uitkomst bijeenkomstfunctie NaN NaN NaN NaN ... Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 049cfd258c174bc49abf17883396d083 NaN NaN POINT (6.01556 51.70976)
9274 38749 Gennep GM0907 1 Zaal Buurman woonfunctie,bijeenkomstfunctie NaN NaN NaN NaN ... Gennep NaN Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 1e8cbe96e72c4c6ba6303f47bec8cdb5 NaN NaN POINT (5.98514 51.70189)

9275 rows × 42 columns

In [88]:
gdf_wims_dedupe = gdf_wims.drop_duplicates(subset ="geometry", keep = False)
df_geojson_dedupe = df_geojson_clean.drop_duplicates(subset ="geometry", keep = False)
gdf_wims_dedupe
Out[88]:
_id Gemeente CBS gemeentecode Nummer stembureau Naam stembureau Gebruiksdoel van het gebouw Website locatie Wijknaam CBS wijknummer Buurtnaam ... Hoofdstembureau Tellocatie Contactgegevens gemeente Verkiezingswebsite gemeente Verkiezingen ID UUID Unnamed: 39 Unnamed: 40 geometry
0 1 Valkenswaard GM0858 1 Zorgcentrum Kempenhof gezondheidszorgfunctie https://www.valkenhof.nl/ NaN NaN NaN ... Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 3a612b2151fa4ab491b9e331355e6258 NaN NaN POINT (5.45515 51.34711)
1 2 Valkenswaard GM0858 2 Buurtgebouw De Horizon bijeenkomstfunctie NaN NaN NaN NaN ... Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 9a01d765af0a467ea37f08d92db114ba NaN NaN POINT (5.45137 51.34955)
2 3 Valkenswaard GM0858 3 Speeltuin Geenhoven bijeenkomstfunctie NaN NaN NaN NaN ... Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 fc5869d33fbc4b06be659149fa615f4c NaN NaN POINT (5.44827 51.35702)
3 4 Valkenswaard GM0858 4 Ontmoetingscentrum De zoete inval bijeenkomstfunctie NaN NaN NaN NaN ... Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 4427cc0b39e040ba8f75c333f19d66f0 NaN NaN POINT (5.44871 51.36022)
4 5 Valkenswaard GM0858 5 Gymnastiekzaal 't Gegraaf sportfunctie NaN NaN NaN NaN ... Valkenswaard NaN verkiezingen@valkenswaard.nl http://www.valkenswaard.nl/verkiezingen NaN NLODSGM0858stembureaus20220316009 a893bb9add324ce29769f1c39afcc48d NaN NaN POINT (5.45331 51.36514)
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
9270 38745 Gennep GM0907 4 Het Hökske bijeenkomstfunctie NaN NaN NaN NaN ... Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 f744546cd6894e5e9a4db4bbfd81b4ee NaN NaN POINT (5.98266 51.69726)
9271 38746 Gennep GM0907 5 Buurthuis VanOns bijeenkomstfunctie NaN NaN NaN NaN ... Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 1270081b1dc74cd7bea0f45973650408 NaN NaN POINT (5.98127 51.69000)
9272 38747 Gennep GM0907 6 't Trefpunt bijeenkomstfunctie NaN NaN NaN NaN ... Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 447c7742604345139e41def4cf1e4d3c NaN NaN POINT (5.95118 51.72591)
9273 38748 Gennep GM0907 8 De Uitkomst bijeenkomstfunctie NaN NaN NaN NaN ... Gennep ja Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 049cfd258c174bc49abf17883396d083 NaN NaN POINT (6.01556 51.70976)
9274 38749 Gennep GM0907 1 Zaal Buurman woonfunctie,bijeenkomstfunctie NaN NaN NaN NaN ... Gennep NaN Klantcontactcentrum gemeente Gennep gemeente@g... https://www.gennep.nl NaN NLODSGM0907stembureaus20220316009 1e8cbe96e72c4c6ba6303f47bec8cdb5 NaN NaN POINT (5.98514 51.70189)

8092 rows × 42 columns

In [89]:
fig, ax = plt.subplots(figsize = (15,15))
nl_map.to_crs(epsg=4326).plot(ax=ax, color='lightgrey')
gdf_wims_dedupe.plot(ax=ax)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb Cell 16' in <cell line: 3>()
      <a href='vscode-notebook-cell:/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb#ch0000015?line=0'>1</a> fig, ax = plt.subplots(figsize = (15,15))
      <a href='vscode-notebook-cell:/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb#ch0000015?line=1'>2</a> nl_map.to_crs(epsg=4326).plot(ax=ax, color='lightgrey')
----> <a href='vscode-notebook-cell:/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb#ch0000015?line=2'>3</a> gdf_wims_dedupe.plot(ax=ax)

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py:950, in GeoplotAccessor.__call__(self, *args, **kwargs)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=947'>948</a> kind = kwargs.pop("kind", "geo")
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=948'>949</a> if kind == "geo":
--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=949'>950</a>     return plot_dataframe(data, *args, **kwargs)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=950'>951</a> if kind in self._pandas_kinds:
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=951'>952</a>     # Access pandas plots
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=952'>953</a>     return PlotAccessor(data)(kind=kind, **kwargs)

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py:692, in plot_dataframe(df, column, cmap, color, ax, cax, categorical, legend, scheme, k, vmin, vmax, markersize, figsize, legend_kwds, categories, classification_kwds, missing_kwds, aspect, **style_kwds)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=688'>689</a>     markersize = df[markersize].values
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=690'>691</a> if column is None:
--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=691'>692</a>     return plot_series(
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=692'>693</a>         df.geometry,
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=693'>694</a>         cmap=cmap,
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=694'>695</a>         color=color,
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=695'>696</a>         ax=ax,
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=696'>697</a>         figsize=figsize,
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=697'>698</a>         markersize=markersize,
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=698'>699</a>         aspect=aspect,
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=699'>700</a>         **style_kwds,
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=700'>701</a>     )
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=702'>703</a> # To accept pd.Series and np.arrays as column
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=703'>704</a> if isinstance(column, (np.ndarray, pd.Series)):

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py:470, in plot_series(s, cmap, color, ax, figsize, aspect, **style_kwds)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=464'>465</a>     values_ = values[point_idx] if cmap else None
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=465'>466</a>     _plot_point_collection(
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=466'>467</a>         ax, points, values_, color=color, cmap=cmap, **style_kwds
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=467'>468</a>     )
--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=469'>470</a> plt.draw()
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/plotting.py?line=470'>471</a> return ax

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/pyplot.py:973, in draw()
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/pyplot.py?line=960'>961</a> def draw():
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/pyplot.py?line=961'>962</a>     """
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/pyplot.py?line=962'>963</a>     Redraw the current figure.
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/pyplot.py?line=963'>964</a> 
   (...)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/pyplot.py?line=970'>971</a>     the current figure.
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/pyplot.py?line=971'>972</a>     """
--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/pyplot.py?line=972'>973</a>     gcf().canvas.draw_idle()

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py:2060, in FigureCanvasBase.draw_idle(self, *args, **kwargs)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2057'>2058</a> if not self._is_idle_drawing:
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2058'>2059</a>     with self._idle_draw_cntx():
-> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2059'>2060</a>         self.draw(*args, **kwargs)

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:436, in FigureCanvasAgg.draw(self)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py?line=431'>432</a> # Acquire a lock on the shared font cache.
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py?line=432'>433</a> with RendererAgg.lock, \
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py?line=433'>434</a>      (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py?line=434'>435</a>       else nullcontext()):
--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py?line=435'>436</a>     self.figure.draw(self.renderer)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py?line=436'>437</a>     # A GUI class may be need to update a window using this draw, so
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py?line=437'>438</a>     # don't forget to call the superclass.
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py?line=438'>439</a>     super().draw()

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py:73, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=70'>71</a> @wraps(draw)
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=71'>72</a> def draw_wrapper(artist, renderer, *args, **kwargs):
---> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=72'>73</a>     result = draw(artist, renderer, *args, **kwargs)
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=73'>74</a>     if renderer._rasterizing:
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=74'>75</a>         renderer.stop_rasterizing()

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py:50, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=46'>47</a>     if artist.get_agg_filter() is not None:
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=47'>48</a>         renderer.start_filter()
---> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=49'>50</a>     return draw(artist, renderer)
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=50'>51</a> finally:
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=51'>52</a>     if artist.get_agg_filter() is not None:

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py:2823, in Figure.draw(self, renderer)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=2819'>2820</a> if not self.get_visible():
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=2820'>2821</a>     return
-> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=2822'>2823</a> artists = self._get_draw_artists(renderer)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=2824'>2825</a> try:
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=2825'>2826</a>     renderer.open_group('figure', gid=self.get_gid())

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py:238, in FigureBase._get_draw_artists(self, renderer)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=235'>236</a>     ax.apply_aspect(pos)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=236'>237</a> else:
--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=237'>238</a>     ax.apply_aspect()
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=239'>240</a> for child in ax.get_children():
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=240'>241</a>     if hasattr(child, 'apply_aspect'):

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py:1895, in _AxesBase.apply_aspect(self, position)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py?line=1892'>1893</a> box_aspect = aspect * self.get_data_ratio()
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py?line=1893'>1894</a> pb = position.frozen()
-> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py?line=1894'>1895</a> pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py?line=1895'>1896</a> self._set_position(pb1.anchored(self.get_anchor(), pb), 'active')
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py?line=1896'>1897</a> return

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py:558, in BboxBase.shrunk_to_aspect(self, box_aspect, container, fig_aspect)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=547'>548</a> """
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=548'>549</a> Return a copy of the `Bbox`, shrunk so that it is as
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=549'>550</a> large as it can be while having the desired aspect ratio,
   (...)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=554'>555</a> ratio of the absolute dimensions, not the relative dimensions.
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=555'>556</a> """
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=556'>557</a> if box_aspect <= 0 or fig_aspect <= 0:
--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=557'>558</a>     raise ValueError("'box_aspect' and 'fig_aspect' must be positive")
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=558'>559</a> if container is None:
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=559'>560</a>     container = self

ValueError: 'box_aspect' and 'fig_aspect' must be positive
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/formatters.py:339, in BaseFormatter.__call__(self, obj)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/formatters.py?line=336'>337</a>     pass
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/formatters.py?line=337'>338</a> else:
--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/formatters.py?line=338'>339</a>     return printer(obj)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/formatters.py?line=339'>340</a> # Finally look for special method names
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/formatters.py?line=340'>341</a> method = get_real_method(obj, self.print_method)

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/pylabtools.py:151, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/pylabtools.py?line=147'>148</a>     from matplotlib.backend_bases import FigureCanvasBase
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/pylabtools.py?line=148'>149</a>     FigureCanvasBase(fig)
--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/pylabtools.py?line=150'>151</a> fig.canvas.print_figure(bytes_io, **kw)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/pylabtools.py?line=151'>152</a> data = bytes_io.getvalue()
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/IPython/core/pylabtools.py?line=152'>153</a> if fmt == 'svg':

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py:2295, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2288'>2289</a>     renderer = _get_renderer(
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2289'>2290</a>         self.figure,
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2290'>2291</a>         functools.partial(
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2291'>2292</a>             print_method, orientation=orientation)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2292'>2293</a>     )
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2293'>2294</a>     with getattr(renderer, "_draw_disabled", nullcontext)():
-> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2294'>2295</a>         self.figure.draw(renderer)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2296'>2297</a> if bbox_inches:
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/backend_bases.py?line=2297'>2298</a>     if bbox_inches == "tight":

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py:73, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=70'>71</a> @wraps(draw)
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=71'>72</a> def draw_wrapper(artist, renderer, *args, **kwargs):
---> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=72'>73</a>     result = draw(artist, renderer, *args, **kwargs)
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=73'>74</a>     if renderer._rasterizing:
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=74'>75</a>         renderer.stop_rasterizing()

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py:50, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=46'>47</a>     if artist.get_agg_filter() is not None:
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=47'>48</a>         renderer.start_filter()
---> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=49'>50</a>     return draw(artist, renderer)
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=50'>51</a> finally:
     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/artist.py?line=51'>52</a>     if artist.get_agg_filter() is not None:

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py:2823, in Figure.draw(self, renderer)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=2819'>2820</a> if not self.get_visible():
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=2820'>2821</a>     return
-> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=2822'>2823</a> artists = self._get_draw_artists(renderer)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=2824'>2825</a> try:
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=2825'>2826</a>     renderer.open_group('figure', gid=self.get_gid())

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py:238, in FigureBase._get_draw_artists(self, renderer)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=235'>236</a>     ax.apply_aspect(pos)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=236'>237</a> else:
--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=237'>238</a>     ax.apply_aspect()
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=239'>240</a> for child in ax.get_children():
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/figure.py?line=240'>241</a>     if hasattr(child, 'apply_aspect'):

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py:1895, in _AxesBase.apply_aspect(self, position)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py?line=1892'>1893</a> box_aspect = aspect * self.get_data_ratio()
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py?line=1893'>1894</a> pb = position.frozen()
-> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py?line=1894'>1895</a> pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect)
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py?line=1895'>1896</a> self._set_position(pb1.anchored(self.get_anchor(), pb), 'active')
   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/axes/_base.py?line=1896'>1897</a> return

File ~/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py:558, in BboxBase.shrunk_to_aspect(self, box_aspect, container, fig_aspect)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=547'>548</a> """
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=548'>549</a> Return a copy of the `Bbox`, shrunk so that it is as
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=549'>550</a> large as it can be while having the desired aspect ratio,
   (...)
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=554'>555</a> ratio of the absolute dimensions, not the relative dimensions.
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=555'>556</a> """
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=556'>557</a> if box_aspect <= 0 or fig_aspect <= 0:
--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=557'>558</a>     raise ValueError("'box_aspect' and 'fig_aspect' must be positive")
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=558'>559</a> if container is None:
    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/matplotlib/transforms.py?line=559'>560</a>     container = self

ValueError: 'box_aspect' and 'fig_aspect' must be positive
<Figure size 1080x1080 with 1 Axes>
In [ ]:
fig, ax = plt.subplots(figsize = (15,15))
nl_map.to_crs(epsg=4326).plot(ax=ax, color='lightgrey')
df_geojson_clean.plot(ax=ax)
Out[ ]:
<AxesSubplot:>
No description has been provided for this image

Nu we een mooie kaart hebben van nederland met de stemlokalen erop, kunnen we gaan kijken naar hoe dit verhoud met de bevolkingsdichtheid als eerste voorbeeld. De kaart is opgehaald van het CBS, eerst gaan we kijken hoe de kaart er op zichzelf met dezelfde projectie uitziet.

In [91]:
nl_map_cbs = gpd.read_file(r'../data/shape/Netherlands_shapefile/cbs_vk500_2021_v1.gpkg')
nl_map_cbs.to_crs(epsg=4326).plot()
Out[91]:
<AxesSubplot:>
No description has been provided for this image

Het verwerken van de 100m bij 100m vierkanten kaar duurde heel lang (langer dan een half uur) op de laptop, en is dus niet ideaal tenzij we dit niveau van detail écht nodig hebben. Er is namelijk nog een andere kaart met dezelfde gegevens beschikbaar, maar met een grid van 500 bij 500 meter in plaats van 100 bij 100. Laten we dus kijken hoe vaak een stemlokaal dichterbij dan 100 meter van de dichtstbijzijnde andere is. De makkelijkste manier om dat te doen zonder alle punten met alle andere te vergelijken (heel veel moeite), is een extra dataframe maken als een kopie, alle indexen 1 opschuiven (want alle stemlokalen zijn al in een volgorde van clustering), en dan de laagste afstand bekijken.

In [92]:
df_shifted = df_geojson_clean.to_crs('EPSG:28992')

df_shifted['geometry (shifted)'] = df_shifted['geometry'].shift(periods=1)
df_shifted['distance'] = df_shifted['geometry'].distance(df_shifted['geometry (shifted)'])
df_shifted.sort_values(['distance'], inplace=True, ascending=True)
zero_mask_booth = df_shifted['distance'] == 0.000000
df_shifted = df_shifted[~zero_mask_booth]
print(df_shifted['distance'])
11165         0.002608
1021          0.004853
3196          0.004875
1923          2.693202
3757          3.609362
             ...      
7444     253385.654588
9711     263408.187856
4392     266925.200994
9297     271954.076837
0                  NaN
Name: distance, Length: 11670, dtype: float64

We kunnen dus vaststellen dat afstanden van onder de 500 meter waarschijnlijk zeldzaam zijn, en we verder kunnen gaan met de 500 meter bij 500 meter kaart. Laten we nu dus een projectie proberen te maken met de bevolkingsdichtheid erop om het te vergelijken met de stemlokalen en hun posities en clustering.

In [ ]:
 
In [95]:
print(list(nl_map_cbs))
nl_map_dst = nl_map_cbs.drop(columns=['aantal_mannen', 'aantal_vrouwen', 'aantal_inwoners_0_tot_15_jaar', 'aantal_inwoners_15_tot_25_jaar', 'aantal_inwoners_25_tot_45_jaar', 'aantal_inwoners_45_tot_65_jaar', 'aantal_inwoners_65_jaar_en_ouder', 'percentage_nederlandse_achtergrond', 'percentage_westerse_migr_achtergr', 'percentage_niet_westerse_migr_achtergr', 'aantal_personen_met_uitkering_onder_aowlft', 'aantal_part_huishoudens', 'aantal_eenpersoonshuishoudens', 'aantal_meerpersoonshuishoudens_zonder_kind', 'aantal_eenouderhuishoudens', 'aantal_tweeouderhuishoudens', 'gemiddelde_huishoudensgrootte', 'aantal_woningen', 'aantal_woningen_bouwjaar_voor_1945', 'aantal_woningen_bouwjaar_45_tot_65', 'aantal_woningen_bouwjaar_65_tot_75', 'aantal_woningen_bouwjaar_75_tot_85', 'aantal_woningen_bouwjaar_85_tot_95', 'aantal_woningen_bouwjaar_95_tot_05', 'aantal_woningen_bouwjaar_05_tot_15', 'aantal_woningen_bouwjaar_15_en_later', 'aantal_meergezins_woningen', 'percentage_koopwoningen', 'percentage_huurwoningen', 'aantal_huurwoningen_in_bezit_woningcorporaties', 'aantal_niet_bewoonde_woningen', 'gemiddelde_woz_waarde_woning', 'omgevingsadressendichtheid'])

nl_map_dst
['crs28992res500m', 'aantal_inwoners', 'aantal_mannen', 'aantal_vrouwen', 'aantal_inwoners_0_tot_15_jaar', 'aantal_inwoners_15_tot_25_jaar', 'aantal_inwoners_25_tot_45_jaar', 'aantal_inwoners_45_tot_65_jaar', 'aantal_inwoners_65_jaar_en_ouder', 'percentage_nederlandse_achtergrond', 'percentage_westerse_migr_achtergr', 'percentage_niet_westerse_migr_achtergr', 'aantal_personen_met_uitkering_onder_aowlft', 'aantal_part_huishoudens', 'aantal_eenpersoonshuishoudens', 'aantal_meerpersoonshuishoudens_zonder_kind', 'aantal_eenouderhuishoudens', 'aantal_tweeouderhuishoudens', 'gemiddelde_huishoudensgrootte', 'aantal_woningen', 'aantal_woningen_bouwjaar_voor_1945', 'aantal_woningen_bouwjaar_45_tot_65', 'aantal_woningen_bouwjaar_65_tot_75', 'aantal_woningen_bouwjaar_75_tot_85', 'aantal_woningen_bouwjaar_85_tot_95', 'aantal_woningen_bouwjaar_95_tot_05', 'aantal_woningen_bouwjaar_05_tot_15', 'aantal_woningen_bouwjaar_15_en_later', 'aantal_meergezins_woningen', 'percentage_koopwoningen', 'percentage_huurwoningen', 'aantal_huurwoningen_in_bezit_woningcorporaties', 'aantal_niet_bewoonde_woningen', 'gemiddelde_woz_waarde_woning', 'omgevingsadressendichtheid', 'stedelijkheid', 'geometry']
Out[95]:
crs28992res500m aantal_inwoners stedelijkheid geometry
0 E2260N6190 -99997 -99997 MULTIPOLYGON (((226000.000 619000.000, 226000....
1 E2265N6190 -99997 -99997 MULTIPOLYGON (((226500.000 619500.000, 227000....
2 E2270N6190 -99997 -99997 MULTIPOLYGON (((227000.000 619500.000, 227500....
3 E2275N6190 -99997 -99997 MULTIPOLYGON (((227500.000 619500.000, 228000....
4 E2280N6190 -99997 -99997 MULTIPOLYGON (((228000.000 619500.000, 228500....
... ... ... ... ...
151103 E1995N3070 -99997 5 MULTIPOLYGON (((199500.000 307500.000, 200000....
151104 E1905N3065 -99997 -99997 MULTIPOLYGON (((190500.000 307000.000, 191000....
151105 E1910N3065 -99997 -99997 MULTIPOLYGON (((191000.000 307000.000, 191500....
151106 E1920N3065 15 5 MULTIPOLYGON (((192000.000 307000.000, 192500....
151107 E1925N3065 -99997 5 MULTIPOLYGON (((192500.000 307000.000, 193000....

151108 rows × 4 columns

We kunnen zien dat er gemeente zijn die geen stemlokalen hebben, dit klopt. In de verkiezingen van 2022 hebben 12 gemeentes niet meegedaan. Er zijn dus in totaal 333 gemeentes met stemlokalen. We willen de bevolkingsdichtheiddata van de gemeentes die niet meededen dus weggooien, hiervoor moeten we eerst kijken welke alleen binnen de gemeentes vallen die we niet willen houden.

In [96]:
print(df_geojson['electionName'])

#get all municipalities that are in the election
gemeentes = df_geojson['electionName'].str.slice(13, -5).drop_duplicates()
print(gemeentes)
0             Gemeenteraad Aa en Hunze 2022
1             Gemeenteraad Aa en Hunze 2022
2             Gemeenteraad Aa en Hunze 2022
3             Gemeenteraad Aa en Hunze 2022
4             Gemeenteraad Aa en Hunze 2022
                        ...                
12591    Gemeenteraad 's-Hertogenbosch 2022
12592    Gemeenteraad 's-Hertogenbosch 2022
12593    Gemeenteraad 's-Hertogenbosch 2022
12594    Gemeenteraad 's-Hertogenbosch 2022
12595    Gemeenteraad 's-Hertogenbosch 2022
Name: electionName, Length: 12596, dtype: object
0             Aa en Hunze
27               Aalsmeer
46                 Aalten
74          Achtkarspelen
95           Alblasserdam
               ...       
11976     Zwartewaterland
11997         Zwijndrecht
12031              Zwolle
12122       's-Gravenhage
12495    's-Hertogenbosch
Name: electionName, Length: 333, dtype: object
In [97]:
#First let's remove the municipalities that don't have an Election from the municipality map
remove_lst = ["Boxtel", "Eemsdelta", "Oisterwijk", "Vught", "Heerhugowaard", "Langedijk", "Boxmeer", "Cuijk", "Sint Anthonis", "Mill en Sint Hubert", "Grave", "Landerd", "Uden", "Brielle", "Hellevoetsluis", "Westvoorne", "Purmerend", "Beemster", "Weesp"]


nl_map_clean = nl_map[~nl_map["GM_NAAM"].isin(remove_lst)]
nl_map_clean = nl_map_clean.query("H2O != 'JA'")
nl_map_clean = nl_map_clean.query("GM_NAAM != 'Buitenland'")


nl_map_election = nl_map[nl_map["GM_NAAM"].isin(gemeentes)]
nl_map_election = nl_map_election.query("H2O != 'JA'")

print("Shape of clean: {}".format(nl_map_clean.shape))
print("Shape of election: {}".format(nl_map_election.shape))

diff = pd.concat([nl_map_election, nl_map_clean]).drop_duplicates(keep=False)
diff
Shape of clean: (333, 38)
Shape of election: (330, 38)
Out[97]:
GM_CODE GM_NAAM H2O OAD STED BEV_DICHTH AANT_INW AANT_MAN AANT_VROUW P_00_14_JR ... P_TURKIJE P_OVER_NW OPP_TOT OPP_LAND OPP_WATER JRSTATCODE JAAR Shape_Leng Shape_Area geometry
113 GM0164 Hengelo NEE 1845 2 1332 81049 40776 40273 15 ... 6 7 6183 6084 99 2021GM0164 2021 47510.255914 6.183056e+07 POLYGON ((251978.591 481220.258, 251979.382 48...
191 GM0373 Bergen (NH.) NEE 819 4 300 29715 14317 15398 12 ... 0 3 12023 9896 2127 2021GM0373 2021 57488.474563 9.987418e+07 POLYGON ((105976.650 529056.951, 106002.347 52...
328 GM0893 Bergen (L.) NEE 318 5 127 13108 6568 6540 13 ... 0 3 10850 10324 525 2021GM0893 2021 61497.563571 1.084951e+08 POLYGON ((199768.270 409749.960, 199758.060 40...

3 rows × 38 columns

Het is een andere vorm omdat deze drie gemeentes een andere format hadden voor de naam van hun verkiezingen, en dus niet op dezelfde manier gefilterd konden worden, ze staan wel in de lijst, dit is dus correct, we gebruiken de clean dataframe. Nu we dezelfde lijst hebben van gemeentes die in de verkiezingen meededen kunnen we verder.

In [98]:
fig, ax = plt.subplots(figsize = (15,15))
nl_map_clean.to_crs(epsg=4326).plot(ax=ax, color='lightgrey')
df_geojson_clean.plot(ax=ax)
Out[98]:
<AxesSubplot:>
No description has been provided for this image
In [99]:
nl_map_dst['savedindex'] = nl_map_dst.index #Save the index values as a new column

intersecting = nl_map_clean.sjoin(nl_map_dst, how='inner')['savedindex'] #Find the polygons that intersect. Keep savedindex as a series

nl_map_dst = nl_map_dst.loc[nl_map_dst.savedindex.isin(intersecting)] #Filter away these, "savedindex is in intersecting"

nl_map_dst.to_crs(epsg=4326).plot()
Out[99]:
<AxesSubplot:>
No description has been provided for this image
In [102]:
import folium
from folium import plugins

#Location is Amersfoort, the central point of the continental Netherlands
map = folium.Map(location = [52.155, 5.3875], zoom_start = 9, tiles="cartodbdark_matter", prefer_canvas=True)

nl_map_dst.to_crs(epsg=4326)
#Make sure the index is a string so folium can read it correctly as a key.
nl_map_dst['crs28992res500m'] = nl_map_dst['crs28992res500m'].apply(lambda x: str(x))

nl_map_dst_zero = nl_map_dst.copy()

zero_mask_pop = nl_map_dst['aantal_inwoners'] == -99997
nl_map_dst = nl_map_dst[~zero_mask_pop]
zero_mask_pop2 = nl_map_dst['aantal_inwoners'] == 0
nl_map_dst = nl_map_dst[~zero_mask_pop2]

folium.Choropleth(
    geo_data = nl_map_dst,
    name="Bevolkingsdichtheid",
    data = nl_map_dst,
    columns = ["crs28992res500m", "aantal_inwoners"],
    key_on = 'feature.properties.crs28992res500m',
    fill_color = 'RdPu',
    nan_fill_color= 'white',
    fill_opacity = 0.7,
    nan_fill_opacity = 0.7,
    line_opacity = 0,
    legend_name = 'Bevolkingsdichtheid',
    smooth_factor = 1.0,
    show=False
).add_to(map)
map

# Renders the map to an HTML file and displays it in an embed.
def embed_map(m):
    #from IPython.display import IFrame
    m.save('index.html')
    #return IFrame('index.html', width='100%', height='750px')
/home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/geopandas/geodataframe.py:1351: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  super().__setitem__(key, value)
In [103]:
gdf_wims_hmp = [[point.xy[1][0], point.xy[0][0]] for point in gdf_wims.geometry]

plugins.HeatMap(gdf_wims_hmp, name="Stemlokalen Heatmap").add_to(map)

folium.LayerControl().add_to(map)



embed_map(map)
In [104]:
nl_map_dst_points = nl_map_dst.copy()
nl_map_dst_points['geometry'] = nl_map_dst_points['geometry'].centroid

nl_map_dst_zero_points = nl_map_dst_zero.copy()
nl_map_dst_zero_points['geometry'] = nl_map_dst_zero_points['geometry'].centroid

nl_map_dst_zero_points
Out[104]:
crs28992res500m aantal_inwoners stedelijkheid geometry savedindex
2 E2270N6190 -99997 -99997 POINT (227250.000 619250.000) 2
3 E2275N6190 -99997 -99997 POINT (227750.000 619250.000) 3
4 E2280N6190 -99997 -99997 POINT (228250.000 619250.000) 4
7 E2265N6185 -99997 -99997 POINT (226750.000 618750.000) 7
8 E2270N6185 -99997 -99997 POINT (227250.000 618750.000) 8
... ... ... ... ... ...
151102 E1990N3070 -99997 -99997 POINT (199250.000 307250.000) 151102
151103 E1995N3070 -99997 5 POINT (199750.000 307250.000) 151103
151105 E1910N3065 -99997 -99997 POINT (191250.000 306750.000) 151105
151106 E1920N3065 15 5 POINT (192250.000 306750.000) 151106
151107 E1925N3065 -99997 5 POINT (192750.000 306750.000) 151107

140002 rows × 5 columns

In [105]:
import numpy as np

from scipy.spatial import cKDTree
from shapely.geometry import Point
#Found on https://gis.stackexchange.com/questions/222315/finding-nearest-point-in-other-geodataframe-using-geopandas
def ckdnearest(gdA, gdB):

    nA = np.array(list(gdA.geometry.apply(lambda x: (x.x, x.y))))
    nB = np.array(list(gdB.geometry.apply(lambda x: (x.x, x.y))))
    btree = cKDTree(nB)
    dist, idx = btree.query(nA, k=1)
    gdB_nearest = gdB.iloc[idx].drop(columns="geometry").reset_index(drop=True)
    gdf = pd.concat(
        [
            gdA.reset_index(drop=True),
            gdB_nearest,
            pd.Series(dist, name='dist')
        ], 
        axis=1)

    return gdf

#error bar is +- sqrt(250²*2)m ≈ +-353.553390593m
error = np.sqrt(250**2 + 250**2)
df_nearest = ckdnearest(nl_map_dst_points.to_crs(epsg=28992), gdf_wims_dedupe.to_crs(epsg=28992))
df_nearest.head()
Out[105]:
crs28992res500m aantal_inwoners stedelijkheid geometry savedindex _id Gemeente CBS gemeentecode Nummer stembureau Naam stembureau ... Hoofdstembureau Tellocatie Contactgegevens gemeente Verkiezingswebsite gemeente Verkiezingen ID UUID Unnamed: 39 Unnamed: 40 dist
0 E2050N6110 5 5 POINT (205250.000 611250.000) 267 30871 Schiermonnikoog GM0088 1 Gemeentehuis (Raadzaal) ... Schiermonnikoog NaN postbus20@schiermonnikoog.nl, 0519-535050 https://www.schiermonnikoog.nl/in-de-gemeente/... NaN NLODSGM0088stembureaus20220316009 35abba36eca7485c89e82b2917633ae7 NaN NaN 1331.950309
1 E2060N6110 10 5 POINT (206250.000 611250.000) 269 30871 Schiermonnikoog GM0088 1 Gemeentehuis (Raadzaal) ... Schiermonnikoog NaN postbus20@schiermonnikoog.nl, 0519-535050 https://www.schiermonnikoog.nl/in-de-gemeente/... NaN NLODSGM0088stembureaus20220316009 35abba36eca7485c89e82b2917633ae7 NaN NaN 688.536284
2 E2055N6105 20 5 POINT (205750.000 610750.000) 292 30871 Schiermonnikoog GM0088 1 Gemeentehuis (Raadzaal) ... Schiermonnikoog NaN postbus20@schiermonnikoog.nl, 0519-535050 https://www.schiermonnikoog.nl/in-de-gemeente/... NaN NLODSGM0088stembureaus20220316009 35abba36eca7485c89e82b2917633ae7 NaN NaN 672.375861
3 E2060N6105 185 5 POINT (206250.000 610750.000) 293 30871 Schiermonnikoog GM0088 1 Gemeentehuis (Raadzaal) ... Schiermonnikoog NaN postbus20@schiermonnikoog.nl, 0519-535050 https://www.schiermonnikoog.nl/in-de-gemeente/... NaN NLODSGM0088stembureaus20220316009 35abba36eca7485c89e82b2917633ae7 NaN NaN 228.220493
4 E2065N6105 335 5 POINT (206750.000 610750.000) 294 30871 Schiermonnikoog GM0088 1 Gemeentehuis (Raadzaal) ... Schiermonnikoog NaN postbus20@schiermonnikoog.nl, 0519-535050 https://www.schiermonnikoog.nl/in-de-gemeente/... NaN NLODSGM0088stembureaus20220316009 35abba36eca7485c89e82b2917633ae7 NaN NaN 389.974214

5 rows × 47 columns

Het was mooier geweest als we het konden filteren op alleen stemgerechtigden en niet op de gehele populatiedichtheid, maar het CBS geeft geen data vrij die daarbij helpt. Er is een categorie voor 0-14 jaar oude mensen, maar niet alle minderjarigen of niet stemgerechtigde. Het moet dus maar met totale bevolkingsdichtheid om een idee te krijgen.

In [108]:
nl_map_dst_zero_points["aantal_inwoners"].mask(nl_map_dst_zero_points["aantal_inwoners"] == -99997, 0, inplace=True)
nl_map_dst_zero_points.head()
df_nearest_zero = ckdnearest(nl_map_dst_zero_points.to_crs(epsg=28992), gdf_wims_dedupe.to_crs(epsg=28992))
df_nearest_zero["aantal_inwoners"].dropna()
df_nearest_zero["dist"].dropna()
df_nearest_zero
Out[108]:
crs28992res500m aantal_inwoners stedelijkheid geometry savedindex _id Gemeente CBS gemeentecode Nummer stembureau Naam stembureau ... Hoofdstembureau Tellocatie Contactgegevens gemeente Verkiezingswebsite gemeente Verkiezingen ID UUID Unnamed: 39 Unnamed: 40 dist
0 E2270N6190 0 -99997 POINT (227250.000 619250.000) 2 31030 Het Hogeland GM1966 1 Dorpshuis Pieterburen ... Het Hogeland NaN verkiezingen@hethogeland.nl https://hethogeland.nl/bestuur-en-organisatie/... NaN NLODSGM1966stembureaus20220316009 6df04b8dd4be4aa3b4a03f221ab5ad17 NaN NaN 17236.920436
1 E2275N6190 0 -99997 POINT (227750.000 619250.000) 3 31030 Het Hogeland GM1966 1 Dorpshuis Pieterburen ... Het Hogeland NaN verkiezingen@hethogeland.nl https://hethogeland.nl/bestuur-en-organisatie/... NaN NLODSGM1966stembureaus20220316009 6df04b8dd4be4aa3b4a03f221ab5ad17 NaN NaN 17280.014918
2 E2280N6190 0 -99997 POINT (228250.000 619250.000) 4 31030 Het Hogeland GM1966 1 Dorpshuis Pieterburen ... Het Hogeland NaN verkiezingen@hethogeland.nl https://hethogeland.nl/bestuur-en-organisatie/... NaN NLODSGM1966stembureaus20220316009 6df04b8dd4be4aa3b4a03f221ab5ad17 NaN NaN 17337.427867
3 E2265N6185 0 -99997 POINT (226750.000 618750.000) 7 31030 Het Hogeland GM1966 1 Dorpshuis Pieterburen ... Het Hogeland NaN verkiezingen@hethogeland.nl https://hethogeland.nl/bestuur-en-organisatie/... NaN NLODSGM1966stembureaus20220316009 6df04b8dd4be4aa3b4a03f221ab5ad17 NaN NaN 16708.725120
4 E2270N6185 0 -99997 POINT (227250.000 618750.000) 8 31030 Het Hogeland GM1966 1 Dorpshuis Pieterburen ... Het Hogeland NaN verkiezingen@hethogeland.nl https://hethogeland.nl/bestuur-en-organisatie/... NaN NLODSGM1966stembureaus20220316009 6df04b8dd4be4aa3b4a03f221ab5ad17 NaN NaN 16738.249149
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
139997 E1990N3070 0 -99997 POINT (199250.000 307250.000) 151102 4103 Vaals GM0981 3 Auw Sjoel ... Vaals NaN Team verkiezingen, verkiezingen2022@vaals.nl http://www.vaals.nl/verkiezingen NaN NLODSGM0981stembureaus20220316009 3dfcfccd163145698a33b19623c5c3f3 NaN NaN 2010.126740
139998 E1995N3070 0 5 POINT (199750.000 307250.000) 151103 4103 Vaals GM0981 3 Auw Sjoel ... Vaals NaN Team verkiezingen, verkiezingen2022@vaals.nl http://www.vaals.nl/verkiezingen NaN NLODSGM0981stembureaus20220316009 3dfcfccd163145698a33b19623c5c3f3 NaN NaN 1949.951758
139999 E1910N3065 0 -99997 POINT (191250.000 306750.000) 151105 29739 Gulpen-Wittem GM1729 7 Gemeenschapshuis Patronaat ... Gulpen-Wittem NaN info@gulpen-wittem.nl 14 043 https://www.gulpen-wittem.nl/onderwerpen/verki... NaN NLODSGM1729stembureaus20220316009 feb9d0a67a2f460f906d0d21e87bf690 NaN NaN 2880.233287
140000 E1920N3065 15 5 POINT (192250.000 306750.000) 151106 29739 Gulpen-Wittem GM1729 7 Gemeenschapshuis Patronaat ... Gulpen-Wittem NaN info@gulpen-wittem.nl 14 043 https://www.gulpen-wittem.nl/onderwerpen/verki... NaN NLODSGM1729stembureaus20220316009 feb9d0a67a2f460f906d0d21e87bf690 NaN NaN 2746.345509
140001 E1925N3065 0 5 POINT (192750.000 306750.000) 151107 29739 Gulpen-Wittem GM1729 7 Gemeenschapshuis Patronaat ... Gulpen-Wittem NaN info@gulpen-wittem.nl 14 043 https://www.gulpen-wittem.nl/onderwerpen/verki... NaN NLODSGM1729stembureaus20220316009 feb9d0a67a2f460f906d0d21e87bf690 NaN NaN 2813.494018

140002 rows × 47 columns

In [109]:
df_nearest.sort_values(by=['dist'], inplace=True)
df_nearest[['Gemeente', 'Naam stembureau', 'dist']]
Out[109]:
Gemeente Naam stembureau dist
47304 Ridderkerk Gemeentehuis 3.835321
32815 Baarn Dorpshuis de Furs 4.000517
5168 Groningen Dorpshuis De Hoeksteen 5.577246
38975 Montfoort Zalencentrum St. Joseph 5.703409
67518 Kerkrade t Westhoes 7.252446
... ... ... ...
23422 Zeewolde Het Kruispunt 8207.619943
22478 Lelystad Gymzaal De Borg 8402.730770
22348 Lelystad Voormalige Scholengemeenschap De Rietlanden 8540.805874
22477 Lelystad Voormalige Scholengemeenschap De Rietlanden 9028.790070
22619 Zeewolde Panta Rhei 9173.600947

68131 rows × 3 columns

In [142]:
def plot_dist(df, label):
    plt.figure(figsize=(13,13))
    df['dist'].plot(kind="hist", weights=df['aantal_inwoners'], figsize=(13,13), density=False,title="Afstand tot Stemlokaal per 500 x 500 m vierkant (minimaal 5 mensen in het vierkant) Staffel {}".format(label), log=True).set_ylabel('Bevolking (Millioenen)')
    plt.figure(figsize=(13,13))
    df.plot.scatter(x = 'aantal_inwoners', y = 'dist', figsize=(13,13), title="Afstand tot Stemlokaal per 500 x 500 m vierkant (minimaal 5 mensen in het vierkant) Staffel {}".format(label), xlabel="Inwoners per 500m² (laagste is 5)", ylabel="Afstand tot stemlokaal (meter)")
    
In [111]:
df_nearest_zero.plot.scatter(x = 'aantal_inwoners', y = 'dist', figsize=(13,13), xlabel="Inwoners per 500m² (inclusief lege (<5 inwoners) vierkanten)", ylabel="Afstand tot stemlokaal (meter)")
Out[111]:
<AxesSubplot:xlabel='Inwoners per 500m² (inclusief lege (<5 inwoners) vierkanten)', ylabel='Afstand tot stemlokaal (meter)'>
No description has been provided for this image
In [112]:
FIGSIZE = (13, 13)
def plot_bargraph_with_groupings(df, groupby, colourby, title, xlabel, ylabel):

    import matplotlib.patches as mpatches


    # Makes the bargraph.
    ax = df[groupby].value_counts().plot(kind='bar',
                                         figsize=FIGSIZE,
                                         title=title)
    

    # display the graph.
    
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
In [113]:
plot_bargraph_with_groupings(gdf_wims_dedupe, 'Gebruiksdoel van het gebouw', 'Gemeente', 'Gebruiksdoelen van Stemlokalen', 'Gebruiksdoel', 'Hoeveelheid Stemlokalen')
No description has been provided for this image

Dit is onbruikbaar, de categorieën moeten elk één balkje zijn, niet zoals dit.

In [130]:
def plot_use (df, label):
    plt.figure(figsize=(13,13))
    df_exploded = df.drop('Gebruiksdoel van het gebouw', axis=1).join(df['Gebruiksdoel van het gebouw'].str.split(',', expand=True).stack().reset_index(level=1,drop=True).rename('Gebruiksdoel van het gebouw'))
    #print(df_exploded)
    plot_bargraph_with_groupings(df_exploded, 'Gebruiksdoel van het gebouw', 'Gemeente', 'Gebruiksdoelen van Stemlokalen Staffel {}'.format(label), 'Gebruiksdoel', 'Hoeveelheid Stemlokalen')
    
In [115]:
wims_count = gdf_wims_dedupe['Gemeente'].value_counts()


geojson_rename = df_geojson_dedupe.rename(columns = {'electionName': 'Gemeente'})
geojson_count = geojson_rename['Gemeente'].str.slice(13, -5).value_counts()

pd.concat([geojson_count, wims_count]).drop_duplicates(keep=False)
Out[115]:
Amsterdam              456
Rotterdam              398
's-Gravenhage          271
Utrecht                162
Breda                   90
Eindhoven               86
Groningen               85
Apeldoorn               71
Enschede                69
Alphen aan den Rijn     66
Leiden                  52
Deventer                51
West Betuwe             37
Waadhoeke               33
Amsterdam              382
Rotterdam              375
's-Gravenhage          258
Utrecht                161
Groningen              122
Breda                   89
Haarlemmermeer          79
Nijmegen                74
's-Hertogenbosch        40
Het Hogeland            39
Zoetermeer              38
Staphorst                2
Name: Gemeente, dtype: int64
In [116]:
gdf_wims_times = gdf_wims_dedupe.loc[:, ('Openingstijden 14-03-2022','Openingstijden 15-03-2022','Openingstijden 16-03-2022', 'UUID', 'Gemeente', 'CBS gemeentecode')]
gdf_wims_split = gdf_wims_times
gdf_wims_split[['Openingstijden 14-03-2022 van', 'Openingstijden 14-03-2022 tot']] = gdf_wims_times['Openingstijden 14-03-2022'].str.split(' tot ',1 , expand=True)
gdf_wims_split[['Openingstijden 15-03-2022 van', 'Openingstijden 15-03-2022 tot']] = gdf_wims_split['Openingstijden 15-03-2022'].str.split(' tot ',1 , expand=True)
gdf_wims_split[['Openingstijden 16-03-2022 van', 'Openingstijden 16-03-2022 tot']] = gdf_wims_split['Openingstijden 16-03-2022'].str.split(' tot ',1 , expand=True)

gdf_wims_split
Out[116]:
Openingstijden 14-03-2022 Openingstijden 15-03-2022 Openingstijden 16-03-2022 UUID Gemeente CBS gemeentecode Openingstijden 14-03-2022 van Openingstijden 14-03-2022 tot Openingstijden 15-03-2022 van Openingstijden 15-03-2022 tot Openingstijden 16-03-2022 van Openingstijden 16-03-2022 tot
0 NaN NaN 2022-03-16T10:00:00 tot 2022-03-16T13:00:00 3a612b2151fa4ab491b9e331355e6258 Valkenswaard GM0858 NaN NaN NaN NaN 2022-03-16T10:00:00 2022-03-16T13:00:00
1 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 9a01d765af0a467ea37f08d92db114ba Valkenswaard GM0858 NaN NaN NaN NaN 2022-03-16T07:30:00 2022-03-16T21:00:00
2 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 fc5869d33fbc4b06be659149fa615f4c Valkenswaard GM0858 NaN NaN NaN NaN 2022-03-16T07:30:00 2022-03-16T21:00:00
3 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 4427cc0b39e040ba8f75c333f19d66f0 Valkenswaard GM0858 NaN NaN NaN NaN 2022-03-16T07:30:00 2022-03-16T21:00:00
4 2022-03-14T07:30:00 tot 2022-03-14T21:00:00 2022-03-15T07:30:00 tot 2022-03-15T21:00:00 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 a893bb9add324ce29769f1c39afcc48d Valkenswaard GM0858 2022-03-14T07:30:00 2022-03-14T21:00:00 2022-03-15T07:30:00 2022-03-15T21:00:00 2022-03-16T07:30:00 2022-03-16T21:00:00
... ... ... ... ... ... ... ... ... ... ... ... ...
9270 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 f744546cd6894e5e9a4db4bbfd81b4ee Gennep GM0907 NaN NaN NaN NaN 2022-03-16T07:30:00 2022-03-16T21:00:00
9271 2022-03-14T07:30:00 tot 2022-03-14T21:00:00 2022-03-15T07:30:00 tot 2022-03-15T21:00:00 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 1270081b1dc74cd7bea0f45973650408 Gennep GM0907 2022-03-14T07:30:00 2022-03-14T21:00:00 2022-03-15T07:30:00 2022-03-15T21:00:00 2022-03-16T07:30:00 2022-03-16T21:00:00
9272 NaN 2022-03-15T07:30:00 tot 2022-03-15T21:00:00 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 447c7742604345139e41def4cf1e4d3c Gennep GM0907 NaN NaN 2022-03-15T07:30:00 2022-03-15T21:00:00 2022-03-16T07:30:00 2022-03-16T21:00:00
9273 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 049cfd258c174bc49abf17883396d083 Gennep GM0907 NaN NaN NaN NaN 2022-03-16T07:30:00 2022-03-16T21:00:00
9274 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 1e8cbe96e72c4c6ba6303f47bec8cdb5 Gennep GM0907 NaN NaN NaN NaN 2022-03-16T07:30:00 2022-03-16T21:00:00

8092 rows × 12 columns

In [117]:
gdf_wims_split[['Openingstijden 14-03-2022 van','Openingstijden 15-03-2022 van','Openingstijden 16-03-2022 van', 'Openingstijden 14-03-2022 tot', 'Openingstijden 15-03-2022 tot','Openingstijden 16-03-2022 tot']] = gdf_wims_split[['Openingstijden 14-03-2022 van','Openingstijden 15-03-2022 van','Openingstijden 16-03-2022 van','Openingstijden 14-03-2022 tot','Openingstijden 15-03-2022 tot','Openingstijden 16-03-2022 tot']].apply(pd.to_datetime, errors='coerce')
gdf_wims_split
Out[117]:
Openingstijden 14-03-2022 Openingstijden 15-03-2022 Openingstijden 16-03-2022 UUID Gemeente CBS gemeentecode Openingstijden 14-03-2022 van Openingstijden 14-03-2022 tot Openingstijden 15-03-2022 van Openingstijden 15-03-2022 tot Openingstijden 16-03-2022 van Openingstijden 16-03-2022 tot
0 NaN NaN 2022-03-16T10:00:00 tot 2022-03-16T13:00:00 3a612b2151fa4ab491b9e331355e6258 Valkenswaard GM0858 NaT NaT NaT NaT 2022-03-16 10:00:00 2022-03-16 13:00:00
1 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 9a01d765af0a467ea37f08d92db114ba Valkenswaard GM0858 NaT NaT NaT NaT 2022-03-16 07:30:00 2022-03-16 21:00:00
2 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 fc5869d33fbc4b06be659149fa615f4c Valkenswaard GM0858 NaT NaT NaT NaT 2022-03-16 07:30:00 2022-03-16 21:00:00
3 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 4427cc0b39e040ba8f75c333f19d66f0 Valkenswaard GM0858 NaT NaT NaT NaT 2022-03-16 07:30:00 2022-03-16 21:00:00
4 2022-03-14T07:30:00 tot 2022-03-14T21:00:00 2022-03-15T07:30:00 tot 2022-03-15T21:00:00 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 a893bb9add324ce29769f1c39afcc48d Valkenswaard GM0858 2022-03-14 07:30:00 2022-03-14 21:00:00 2022-03-15 07:30:00 2022-03-15 21:00:00 2022-03-16 07:30:00 2022-03-16 21:00:00
... ... ... ... ... ... ... ... ... ... ... ... ...
9270 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 f744546cd6894e5e9a4db4bbfd81b4ee Gennep GM0907 NaT NaT NaT NaT 2022-03-16 07:30:00 2022-03-16 21:00:00
9271 2022-03-14T07:30:00 tot 2022-03-14T21:00:00 2022-03-15T07:30:00 tot 2022-03-15T21:00:00 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 1270081b1dc74cd7bea0f45973650408 Gennep GM0907 2022-03-14 07:30:00 2022-03-14 21:00:00 2022-03-15 07:30:00 2022-03-15 21:00:00 2022-03-16 07:30:00 2022-03-16 21:00:00
9272 NaN 2022-03-15T07:30:00 tot 2022-03-15T21:00:00 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 447c7742604345139e41def4cf1e4d3c Gennep GM0907 NaT NaT 2022-03-15 07:30:00 2022-03-15 21:00:00 2022-03-16 07:30:00 2022-03-16 21:00:00
9273 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 049cfd258c174bc49abf17883396d083 Gennep GM0907 NaT NaT NaT NaT 2022-03-16 07:30:00 2022-03-16 21:00:00
9274 NaN NaN 2022-03-16T07:30:00 tot 2022-03-16T21:00:00 1e8cbe96e72c4c6ba6303f47bec8cdb5 Gennep GM0907 NaT NaT NaT NaT 2022-03-16 07:30:00 2022-03-16 21:00:00

8092 rows × 12 columns

In [ ]:
import datetime as dt
wims_datemerge = pd.DataFrame()
def datesplit(df, column):
    df = df.dropna(subset = ['{} van'.format(column)])
    df1 = df.rename(columns={'{} van'.format(column):'vandate','{} tot'.format(column):'totdate', 'UUID':'UUID'})
    return  (pd.concat([pd.Series(r.UUID,pd.date_range(r.vandate, r.totdate, freq='0.5H')) 
                        for r in df1.itertuples()])
               .rename_axis('Openingstijden')
               .reset_index(name='UUID'))
def plot_opening(df, label):
    plt.figure(figsize=(13,13))
    wims_datesplit_14 = df.loc[:, ('Openingstijden 14-03-2022 van','Openingstijden 14-03-2022 tot', 'UUID')]
    wims_datesplit_15 = df.loc[:, ('Openingstijden 15-03-2022 van','Openingstijden 15-03-2022 tot', 'UUID')]
    wims_datesplit_16 = df.loc[:, ('Openingstijden 16-03-2022 van','Openingstijden 16-03-2022 tot', 'UUID')]
    wims_datesplit_14 = datesplit(wims_datesplit_14, 'Openingstijden 14-03-2022')
    wims_datesplit_15 = datesplit(wims_datesplit_15, 'Openingstijden 15-03-2022')
    wims_datesplit_16 = datesplit(wims_datesplit_16, 'Openingstijden 16-03-2022')

    wims_datesplit_14.reset_index()
    wims_datesplit_15.reset_index()
    wims_datesplit_16.reset_index()

    #wims_datesplit_14.info()
    #wims_datesplit_15.info()
    #wims_datesplit_16.info()

    
    wims_datestack = pd.concat([wims_datesplit_14, wims_datesplit_15], ignore_index=True)
    wims_datestack = pd.concat([wims_datestack, wims_datesplit_16], ignore_index=True)
    

    

    wims_datestack.set_index('Openingstijden', drop=False, inplace=True)

    #print(wims_datestack['Openingstijden'].unique())

    xticks = []
    xticklabels = []
    datetimecount = 0
    for datetime in wims_datestack.groupby(pd.Grouper(freq='30Min'))['Openingstijden'].unique():
        if (datetime.size > 0):
            xticks.append(datetime.ravel()[0])
            if(datetimecount % 6 == 0):
                ts = pd.to_datetime(datetime.ravel()[0])
                #hardcoded for the data, sloppy code, quick fix, only applies to timestamps with 7 minute changes to reality
                if (ts.minute == 7):
                    ts = ts - dt.timedelta(minutes=7)
                xticklabels.append(ts.strftime("%m-%d %H:%M"))
            else:
                xticklabels.append(" ")
        else:
            xticks.append("")
            xticklabels.append("")
        datetimecount += 1


    wims_datestack.groupby(pd.Grouper(freq='30Min')).count().plot(kind='bar', y='Openingstijden',width=1, figsize=(25, 25), title="Openingstijden stemlokalen staffel {} kiesgerechtigden".format(label)).set_xticklabels(xticklabels, rotation=-45, ha="left", rotation_mode="anchor")
    #TODO: export excel file

    #wims_datesplit_16.groupby(wims_datesplit_16["Openingstijden 16-03-2022"].dt.hour).count().plot(kind="bar", y='Openingstijden 16-03-2022')
    #wims_datesplit_16.groupby(pd.Grouper(freq='30Min')).count().plot(kind='bar', y='Openingstijden 16-03-2022')
    #wims_datesplit_15.groupby(wims_datesplit_15["Openingstijden 15-03-2022"].dt.hour).count().plot(kind="bar", y='Openingstijden 15-03-2022')
    #wims_datesplit_14.groupby(wims_datesplit_14["Openingstijden 14-03-2022"].dt.hour).count().plot(kind="bar", y='Openingstijden 14-03-2022')
In [122]:
df_stemger = pd.read_excel('../data/Maatwerk_kiesgerechtigd_per_gemeente_def.xlsx', sheet_name='Tabel 1', header=0, skiprows= [0,1,3,5,6,7,344,345])
df_stemger_clean = df_stemger[df_stemger['gemeentecode'].isin(nl_map_clean['GM_CODE'])]

bins = [0, 1, 3, 6, 10, 35, float("inf")]
labels = ['0-10.000', '10.000-30.000', '30.000-60.000', '60.000-100.000', '100.000-350.000', '350.000+']

df_stemger_clean['binned'] = pd.cut(df_stemger_clean['Kiesgerechtigde bevolking'], bins, labels=labels)
/tmp/ipykernel_112022/2535562662.py:7: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df_stemger_clean['binned'] = pd.cut(df_stemger_clean['Kiesgerechtigde bevolking'], bins, labels=labels)
In [134]:
def filter_binned(df1, df2):
    return df1[df1['CBS gemeentecode'].isin(df2['gemeentecode'])]

def make_graphs_opening(label):
    df_stemger_label = df_stemger_clean[df_stemger_clean['binned'].str.contains(label)]
    #df_stemger_label.head()
    graph_wims = filter_binned(gdf_wims_dedupe, df_stemger_label)
    graph_wims_split = filter_binned(gdf_wims_split, df_stemger_label)
    plot_opening(graph_wims_split, label)
    
    
for label in labels:
    make_graphs_opening(label)
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
In [133]:
def make_graphs_use(label):
    df_stemger_label = df_stemger_clean[df_stemger_clean['binned'].str.contains(label)]
    plot_use(filter_binned(gdf_wims_dedupe, df_stemger_label), label)

for label in labels:
    make_graphs_use(label)
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [143]:
def make_graphs_dist(label):
    df_stemger_label = df_stemger_clean[df_stemger_clean['binned'].str.contains(label)]
    plot_dist(filter_binned(df_nearest, df_stemger_label), label)

for label in labels:
    make_graphs_dist(label)
No description has been provided for this image
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
No description has been provided for this image
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
No description has been provided for this image
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
No description has been provided for this image
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
No description has been provided for this image
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
No description has been provided for this image
<Figure size 936x936 with 0 Axes>
No description has been provided for this image
In [ ]:
#de eerste vijf rijen zijn meta-data en kunnen we gerust weghalen voor nu 
df_gr_gr = pd.read_csv(r'../data/stemmen/01_Groningen/osv4-3_telling_gr2022_groningen.csv', skiprows=5, header=None, delimiter=';')
print(df_gr_gr)
              0                    1           2                3       4    \
0     Lijstnummer           Aanduiding  Volgnummer   Naam kandidaat  Totaal   
1    Gebiednummer                  NaN         NaN              NaN     NaN   
2        Postcode                  NaN         NaN              NaN     NaN   
3             NaN         opgeroepenen         NaN              NaN  194113   
4             NaN      geldige stempas         NaN              NaN   96830   
..            ...                  ...         ...              ...     ...   
445           NaN                  NaN           5     Oetomo, A.D.      38   
446           NaN                  NaN           6         Smid, D.      25   
447           NaN                  NaN           7  van Welij, P.Z.      10   
448            16  Blanco (Dokter, T.)         NaN              NaN     100   
449           NaN                  NaN           1       Dokter, T.     100   

                                5    \
0    GRID Grafisch Museum Groningen   
1                               101   
2                           9712 JN   
3                              1396   
4                               560   
..                              ...   
445                               0   
446                               0   
447                               0   
448                               0   
449                               0   

                                            6    \
0    Gemeente Groningen (locatie Kreupelstraat)   
1                                           102   
2                                       9712 HW   
3                                          1311   
4                                           469   
..                                          ...   
445                                           0   
446                                           0   
447                                           0   
448                                           0   
449                                           0   

                                            7            8            9    \
0    Gemeente Groningen (locatie Kreupelstraat)  Der Aa-kerk  Der Aa-kerk   
1                                           103          104          105   
2                                       9712 HW      9711 JB      9711 JB   
3                                          1311         1311         1311   
4                                           491          595          607   
..                                          ...          ...          ...   
445                                           0            0            0   
446                                           0            0            0   
447                                           0            0            0   
448                                           0            0            0   
449                                           0            0            0   

     ...              175         176              177                  178  \
0    ...  MFC 't Vinkhuys  De Fontein  Trefpunt Beijum  Wijkcentrum Het Dok   
1    ...              827         828              829                  830   
2    ...          9743 BJ     9741 EZ          9737 AB              9733 CA   
3    ...                0           0                0                    0   
4    ...              369         503              367                  537   
..   ...              ...         ...              ...                  ...   
445  ...                0           0                0                    0   
446  ...                0           2                0                    0   
447  ...                0           0                0                    0   
448  ...                2           2                1                    0   
449  ...                2           2                1                    0   

                      179                     180  \
0    PKN Blister Ten Boer  Buurtcentrum Stadspark   
1                     831                     832   
2                 9791 CP                 9727 HW   
3                       0                       0   
4                     218                     283   
..                    ...                     ...   
445                     0                       0   
446                     0                       0   
447                     0                       0   
448                     0                       2   
449                     0                       2   

                                           181            182  \
0    Kerk van J.C. van de H. der Laatste Dagen  Maranathakerk   
1                                          833            834   
2                                      9728 AR        9721 PE   
3                                            0              0   
4                                          302            473   
..                                         ...            ...   
445                                          0              0   
446                                          3              0   
447                                          0              1   
448                                          0              0   
449                                          0              0   

                             183                 184  
0    Tennispark Vorenkamp (GLTB)  Gemeentehuis Haren  
1                            835                 836  
2                        9722 HJ             9751 AN  
3                              0                   0  
4                            495                 815  
..                           ...                 ...  
445                            0                   0  
446                            0                   0  
447                            0                   0  
448                            0                   0  
449                            0                   0  

[450 rows x 185 columns]

De data is heel gecompliceerd, dus we moeten het bruikbaar maken in pandas. Met hoe de data eruit ziet in een CSV in libre office willen we een constructie maken van de verschillende onderdelen. We hebben de data van de stemlokalen apart al, die kunnen we dus negeren. We willen de data van de lijsten apart hebben.

In [ ]:
#TODO:mobiele stemlokalen eruit filteren die NIET 0,0 zijn
#TODO:datastandaard duitse verkiezingen stemlokaalafstand opzoeken
</html>