{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Datasets gemeenteraadsverkiezingen 2022\n",
    "Deze notebook heeft als doel de stemlokalen van de gemeenteraadsverkiezingen van 2022 te analyseren. 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 van de overheid als van 'Waar is mijn stemlokaal' (voor geografische data van de stemlokalen). Deze bronnen zijn voor de verkiezingen van 2022 gebruikt:\n",
    "- [Verkiezingsuitslagen Gemeenteraad 2022](https://data.overheid.nl/dataset/08b04bec-3332-4c76-bb0c-68bfaeb5df43)\n",
    "  - [Directe link naar uitslagen per gemeente EML](https://data.overheid.nl/sites/default/files/dataset/08b04bec-3332-4c76-bb0c-68bfaeb5df43/resources/GR2022_2022-03-29T15.14.zip)\n",
    "  - [Directe link naar kandidatenlijst met uitslagen CSV](https://data.overheid.nl/sites/default/files/dataset/08b04bec-3332-4c76-bb0c-68bfaeb5df43/resources/GR2022_alle-kandidaten_2022-02-22T08.34.csv)\n",
    "- ['Waar is mijn stemlokaal' stembureau data](https://waarismijnstemlokaal.nl/data)\n",
    "  - [Directe link naar 'Waar is mijn stemlokaal' gemeenteraad 2022 CSV (CKAN)](https://ckan.dataplatform.nl/datastore/dump/d6a1b4c4-73c8-457b-9b75-a38428bded68)\n",
    "  - [Verkiezingsuitslagen gemeenteraadsverkiezingen 2022 geodata vab Open State Foundation en de Volkskrant (OSF/VK)](https://data.openstate.eu/dataset/verkiezingsuitslagen-gemeenteraadsverkiezingen-2022)\n",
    "    - [Directe link naar GeoJSON bestand](https://data.openstate.eu/dataset/a1767f1b-bf0c-409b-b3b1-3af9954b57f4/resource/413be255-5070-48f4-b631-895097976abb/download/2022gr.geo.json)\n",
    "- [CBS Wijk- en buurtkaart 2021](https://www.cbs.nl/nl-nl/dossier/nederland-regionaal/geografische-data/wijk-en-buurtkaart-2021)\n",
    "  - [Directe link naar zip bestand met SHP bestand er in](https://www.cbs.nl/-/media/cbs/dossiers/nederland-regionaal/wijk-en-buurtstatistieken/wijkbuurtkaart_2021_v1.zip)\n",
    "- [CBS bevolkingsdichtheid kaart 100 bij 100 meter](https://www.cbs.nl/nl-nl/dossier/nederland-regionaal/geografische-data/kaart-van-100-meter-bij-100-meter-met-statistieken)\n",
    "  - [Directe link naar 7z bestand met SHP bestand er in](https://www.cbs.nl/-/media/cbs/dossiers/nederland-regionaal/vierkanten/100/nl_vierkant_100meter_bij_100meter.7z)\n",
    "- [CBS bevolkingsdichtheid kaart 500 bij 500 meter](https://www.cbs.nl/nl-nl/dossier/nederland-regionaal/geografische-data/kaart-van-500-meter-bij-500-meter-met-statistieken)\n",
    "  - [Directe link naar 7z bestand met SHP bestand er in](https://www.cbs.nl/-/media/cbs/dossiers/nederland-regionaal/vierkanten/500/2021-cbs_vk500_2020_v1.zip)\n",
    "- [CBS schatting van kiesgerechtigden per gemeente](https://www.cbs.nl/nl-nl/maatwerk/2020/52/schatting-van-het-aantal-kiesgerechtigden-in-nederland)\n",
    "\n",
    "# Data inladen en eerste analyse\n",
    "## OSF/VK GeoJSON dataset: verkiezingsuitslagen per stembureau inclusief coördinaten\n",
    "Als eerste importeren we de data voor de analyse, daarna kunnen we kijken hoe goed de data is, hoe we het aan kunnen vullen, en wat er mee te doen. We kijken eerst naar het GeoJSON bestand van Open State Foundation en de Volkskrant (OSF/VK). Daarin zijn de coördinaten van alle locaties van bijna alle stembureaus toegevoegd aan de lijst met stembureaus uit de officiële uitslagen zoals gepubliceerd door de Kiesraad. We kunnen een GeoJSON bestand direct inladen met geopandas."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import geopandas as gpd\n",
    "\n",
    "crs = {'init':'EPSG:4326'}\n",
    "df_geojson = gpd.read_file(r'../data/2022gr.geo.json', crs=crs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## CBS dataset: gemeentegrenzen en informatie\n",
    "We importeren nu de gemeente shapefile kaart van het CBS, om de overlay van onze stemlokalen eroverheen te leggen."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:title={'center':'Plot van de gemeenten uit de CBS Wijk- en buurtkaart 2021'}>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 49796 characters]",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "nl_map = gpd.read_file(r'../data/shape/Netherlands_shapefile/gemeente_2021_v1.shp')\n",
    "plot = nl_map.to_crs(epsg=4326).plot()\n",
    "plot.set_title('Plot van de gemeenten uit de CBS Wijk- en buurtkaart 2021')\n",
    "plot\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "De CBS Wijk- en buurtkaart 2021 bevat ook naast de gemeentegrenzen ook informatie (bv. aantal inwoners) over de gemeenten. We printen dat hier uit om daar een beeld van te krijgen."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    GM_CODE            GM_NAAM  H2O       OAD      STED  BEV_DICHTH  AANT_INW  \\\n",
      "0    GM0034             Almere   JA -99999999 -99999999   -99999999 -99999999   \n",
      "1    GM0050           Zeewolde   JA -99999999 -99999999   -99999999 -99999999   \n",
      "2    GM0060            Ameland   JA -99999999 -99999999   -99999999 -99999999   \n",
      "3    GM0072          Harlingen   JA -99999999 -99999999   -99999999 -99999999   \n",
      "4    GM0088    Schiermonnikoog   JA -99999999 -99999999   -99999999 -99999999   \n",
      "..      ...                ...  ...       ...       ...         ...       ...   \n",
      "430  GM1966       Het Hogeland  NEE       414         5          99     47834   \n",
      "431  GM1969     Westerkwartier  NEE       476         5         176     63678   \n",
      "432  GM1970  Noardeast-Fryslân  NEE       463         5         120     45481   \n",
      "433  GM1978        Molenlanden  NEE       393         5         243     44130   \n",
      "434  GM1979          Eemsdelta  NEE       692         4         170     45587   \n",
      "\n",
      "     AANT_MAN  AANT_VROUW  P_00_14_JR  ...  P_TURKIJE  P_OVER_NW   OPP_TOT  \\\n",
      "0   -99999999   -99999999   -99999999  ...  -99999999  -99999999 -99999999   \n",
      "1   -99999999   -99999999   -99999999  ...  -99999999  -99999999 -99999999   \n",
      "2   -99999999   -99999999   -99999999  ...  -99999999  -99999999 -99999999   \n",
      "3   -99999999   -99999999   -99999999  ...  -99999999  -99999999 -99999999   \n",
      "4   -99999999   -99999999   -99999999  ...  -99999999  -99999999 -99999999   \n",
      "..        ...         ...         ...  ...        ...        ...       ...   \n",
      "430     24052       23782          15  ...          0          3     90308   \n",
      "431     32034       31644          17  ...          0          3     36887   \n",
      "432     22879       22602          17  ...          0          2     51645   \n",
      "433     22317       21813          18  ...          0          2     19158   \n",
      "434     22841       22746          14  ...          2          5     36407   \n",
      "\n",
      "     OPP_LAND  OPP_WATER  JRSTATCODE  JAAR     Shape_Leng    Shape_Area  \\\n",
      "0   -99999999  -99999999  2021GM0034  2021  122665.358635  1.095623e+08   \n",
      "1   -99999999  -99999999  2021GM0050  2021   83290.773617  1.633050e+07   \n",
      "2   -99999999  -99999999  2021GM0060  2021  156406.894023  2.085914e+08   \n",
      "3   -99999999  -99999999  2021GM0072  2021  104274.683035  3.618323e+08   \n",
      "4   -99999999  -99999999  2021GM0088  2021  152568.858991  1.624101e+08   \n",
      "..        ...        ...         ...   ...            ...           ...   \n",
      "430     48249      42059  2021GM1966  2021  321301.166576  4.875998e+08   \n",
      "431     36269        618  2021GM1969  2021   99030.762281  3.688457e+08   \n",
      "432     37783      13862  2021GM1970  2021  238426.959926  3.837930e+08   \n",
      "433     18173        986  2021GM1978  2021   88570.376691  1.915841e+08   \n",
      "434     26789       9618  2021GM1979  2021  173966.493452  2.727771e+08   \n",
      "\n",
      "                                              geometry  \n",
      "0    MULTIPOLYGON (((150213.998 479503.726, 150087....  \n",
      "1    MULTIPOLYGON (((170588.413 486792.192, 170570....  \n",
      "2    POLYGON ((196000.000 610000.000, 196000.000 60...  \n",
      "3    MULTIPOLYGON (((158392.775 580357.500, 158387....  \n",
      "4    POLYGON ((219000.000 616567.418, 219000.000 61...  \n",
      "..                                                 ...  \n",
      "430  MULTIPOLYGON (((217037.735 601967.991, 217043....  \n",
      "431  POLYGON ((215186.661 595044.495, 215190.788 59...  \n",
      "432  MULTIPOLYGON (((207769.575 603284.528, 207773....  \n",
      "433  POLYGON ((123569.533 440132.167, 123576.153 44...  \n",
      "434  MULTIPOLYGON (((269190.000 594253.046, 269190....  \n",
      "\n",
      "[435 rows x 38 columns]\n"
     ]
    }
   ],
   "source": [
    "print(nl_map)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Hieronder plotten we de gegevens van stembureaus op de kaart van het CBS:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Stembureaus op de gemeentekaart van het CBS')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 9672 characters]",
      "text/plain": [
       "<Figure size 720x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "fig, ax = plt.subplots(figsize = (10,10))\n",
    "nl_map.to_crs(epsg=4326).plot(ax=ax, color='lightgrey')\n",
    "df_geojson.plot(ax=ax)\n",
    "ax.set_title('Stembureaus op de gemeentekaart van het CBS')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "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."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stembureau                                     32\n",
      "Adres                                            \n",
      "Locatie                                      SB32\n",
      "description        Stembureau Mobiel Stembureau 1\n",
      "Geldige stemmen                                99\n",
      "                                ...              \n",
      "één-Ermelo                                    NaN\n",
      "gmcode                                     GM0109\n",
      "election                         GR2022_Coevorden\n",
      "electionName          Gemeenteraad Coevorden 2022\n",
      "geometry                              POINT (0 0)\n",
      "Name: 2520, Length: 973, dtype: object\n",
      "Stembureau                                     33\n",
      "Adres                                            \n",
      "Locatie                                      SB33\n",
      "description        Stembureau Mobiel Stembureau 2\n",
      "Geldige stemmen                               115\n",
      "                                ...              \n",
      "één-Ermelo                                    NaN\n",
      "gmcode                                     GM0109\n",
      "election                         GR2022_Coevorden\n",
      "electionName          Gemeenteraad Coevorden 2022\n",
      "geometry                              POINT (0 0)\n",
      "Name: 2521, Length: 973, dtype: object\n",
      "Stembureau                                   157\n",
      "Adres                                           \n",
      "Locatie                                    SB157\n",
      "description        Stembureau Stembureau Stembus\n",
      "Geldige stemmen                               72\n",
      "                               ...              \n",
      "één-Ermelo                                   NaN\n",
      "gmcode                                    GM0150\n",
      "election                         GR2022_Deventer\n",
      "electionName          Gemeenteraad Deventer 2022\n",
      "geometry                             POINT (0 0)\n",
      "Name: 2918, Length: 973, dtype: object\n",
      "Stembureau                                                       171\n",
      "Adres                                                               \n",
      "Locatie                                                        SB171\n",
      "description        Stembureau Stembureau Stembureau op locatie al...\n",
      "Geldige stemmen                                                  174\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0772\n",
      "election                                            GR2022_Eindhoven\n",
      "electionName                             Gemeenteraad Eindhoven 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 3579, Length: 973, dtype: object\n",
      "Stembureau                                                       172\n",
      "Adres                                                               \n",
      "Locatie                                                        SB172\n",
      "description        Stembureau Stembureau Stembureau op locatie al...\n",
      "Geldige stemmen                                                   66\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0772\n",
      "election                                            GR2022_Eindhoven\n",
      "electionName                             Gemeenteraad Eindhoven 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 3580, Length: 973, dtype: object\n",
      "Stembureau                                                       173\n",
      "Adres                                                               \n",
      "Locatie                                                        SB173\n",
      "description        Stembureau Stembureau Stembureau op locatie al...\n",
      "Geldige stemmen                                                  162\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0772\n",
      "election                                            GR2022_Eindhoven\n",
      "electionName                             Gemeenteraad Eindhoven 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 3581, Length: 973, dtype: object\n",
      "Stembureau                                                       174\n",
      "Adres                                                               \n",
      "Locatie                                                        SB174\n",
      "description        Stembureau Stembureau Stembureau op locatie al...\n",
      "Geldige stemmen                                                   65\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0772\n",
      "election                                            GR2022_Eindhoven\n",
      "electionName                             Gemeenteraad Eindhoven 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 3582, Length: 973, dtype: object\n",
      "Stembureau                                                       175\n",
      "Adres                                                               \n",
      "Locatie                                                        SB175\n",
      "description        Stembureau Stembureau Stembureau op locatie al...\n",
      "Geldige stemmen                                                  121\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0772\n",
      "election                                            GR2022_Eindhoven\n",
      "electionName                             Gemeenteraad Eindhoven 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 3583, Length: 973, dtype: object\n",
      "Stembureau                                                        39\n",
      "Adres                                                               \n",
      "Locatie                                                         SB39\n",
      "description        Stembureau Mobiel stembureau met beperkte toeg...\n",
      "Geldige stemmen                                                   56\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM1735\n",
      "election                                         GR2022_HofvanTwente\n",
      "electionName                        Gemeenteraad Hof van Twente 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 5494, Length: 973, dtype: object\n",
      "Stembureau                                                        34\n",
      "Adres                                                               \n",
      "Locatie                                                         SB34\n",
      "description        Stembureau Stembureau Mobiel stembureau verzor...\n",
      "Geldige stemmen                                                  119\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0166\n",
      "election                                               GR2022_Kampen\n",
      "electionName                                Gemeenteraad Kampen 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 5784, Length: 973, dtype: object\n",
      "Stembureau                                                        35\n",
      "Adres                                                               \n",
      "Locatie                                                         SB35\n",
      "description        Stembureau Stembureau Mobiel stembureau verzor...\n",
      "Geldige stemmen                                                  151\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0166\n",
      "election                                               GR2022_Kampen\n",
      "electionName                                Gemeenteraad Kampen 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 5785, Length: 973, dtype: object\n",
      "Stembureau                                            11\n",
      "Adres                                                   \n",
      "Locatie                                             SB11\n",
      "description        Stembureau Mobiel stembureau Ommedijk\n",
      "Geldige stemmen                                       14\n",
      "                                   ...                  \n",
      "één-Ermelo                                           NaN\n",
      "gmcode                                            GM0547\n",
      "election                               GR2022_Leiderdorp\n",
      "electionName                Gemeenteraad Leiderdorp 2022\n",
      "geometry                                     POINT (0 0)\n",
      "Name: 6260, Length: 973, dtype: object\n",
      "Stembureau                                                        12\n",
      "Adres                                                               \n",
      "Locatie                                                         SB12\n",
      "description        Stembureau Mobiel stembureau Van Alphenstaete ...\n",
      "Geldige stemmen                                                   68\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0547\n",
      "election                                           GR2022_Leiderdorp\n",
      "electionName                            Gemeenteraad Leiderdorp 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 6261, Length: 973, dtype: object\n",
      "Stembureau                                   70\n",
      "Adres                                          \n",
      "Locatie                                    SB70\n",
      "description        Stembureau Mobiel stembureau\n",
      "Geldige stemmen                              34\n",
      "                               ...             \n",
      "één-Ermelo                                  NaN\n",
      "gmcode                                   GM0938\n",
      "election                        GR2022_Meerssen\n",
      "electionName         Gemeenteraad Meerssen 2022\n",
      "geometry                            POINT (0 0)\n",
      "Name: 6738, Length: 973, dtype: object\n",
      "Stembureau                                   71\n",
      "Adres                                          \n",
      "Locatie                                    SB71\n",
      "description        Stembureau Mobiel stembureau\n",
      "Geldige stemmen                              43\n",
      "                               ...             \n",
      "één-Ermelo                                  NaN\n",
      "gmcode                                   GM0938\n",
      "election                        GR2022_Meerssen\n",
      "electionName         Gemeenteraad Meerssen 2022\n",
      "geometry                            POINT (0 0)\n",
      "Name: 6739, Length: 973, dtype: object\n",
      "Stembureau                                             699\n",
      "Adres                                                     \n",
      "Locatie                                              SB699\n",
      "description        Stembureau Stembureau Mobiel stembureau\n",
      "Geldige stemmen                                         59\n",
      "                                    ...                   \n",
      "één-Ermelo                                             NaN\n",
      "gmcode                                              GM0687\n",
      "election                                 GR2022_Middelburg\n",
      "electionName                  Gemeenteraad Middelburg 2022\n",
      "geometry                                       POINT (0 0)\n",
      "Name: 6863, Length: 973, dtype: object\n",
      "Stembureau                                   32\n",
      "Adres                                          \n",
      "Locatie                                    SB32\n",
      "description         Stembureau Mobielstembureau\n",
      "Geldige stemmen                              63\n",
      "                               ...             \n",
      "één-Ermelo                                  NaN\n",
      "gmcode                                   GM1930\n",
      "election                      GR2022_Nissewaard\n",
      "electionName       Gemeenteraad Nissewaard 2022\n",
      "geometry                            POINT (0 0)\n",
      "Name: 7348, Length: 973, dtype: object\n",
      "Stembureau                                   90\n",
      "Adres                                          \n",
      "Locatie                                    SB90\n",
      "description            Stembureau Roll and Vote\n",
      "Geldige stemmen                             339\n",
      "                               ...             \n",
      "één-Ermelo                                  NaN\n",
      "gmcode                                   GM1930\n",
      "election                      GR2022_Nissewaard\n",
      "electionName       Gemeenteraad Nissewaard 2022\n",
      "geometry                            POINT (0 0)\n",
      "Name: 7364, Length: 973, dtype: object\n",
      "Stembureau                                   19\n",
      "Adres                                          \n",
      "Locatie                                    SB19\n",
      "description        Stembureau Mobiel stembureau\n",
      "Geldige stemmen                              77\n",
      "                               ...             \n",
      "één-Ermelo                                  NaN\n",
      "gmcode                                   GM0086\n",
      "election                      GR2022_Opsterland\n",
      "electionName       Gemeenteraad Opsterland 2022\n",
      "geometry                            POINT (0 0)\n",
      "Name: 7857, Length: 973, dtype: object\n",
      "Stembureau                                                    1428\n",
      "Adres                                                             \n",
      "Locatie                                                     SB1428\n",
      "description        Stembureau Drive-thru parkeerplaats Rusheuvel 1\n",
      "Geldige stemmen                                                163\n",
      "                                        ...                       \n",
      "één-Ermelo                                                     NaN\n",
      "gmcode                                                      GM0828\n",
      "election                                                GR2022_Oss\n",
      "electionName                                 Gemeenteraad Oss 2022\n",
      "geometry                                               POINT (0 0)\n",
      "Name: 7912, Length: 973, dtype: object\n",
      "Stembureau                                                    1437\n",
      "Adres                                                             \n",
      "Locatie                                                     SB1437\n",
      "description        Stembureau Drive-thru parkeerplaats Rusheuvel 2\n",
      "Geldige stemmen                                                239\n",
      "                                        ...                       \n",
      "één-Ermelo                                                     NaN\n",
      "gmcode                                                      GM0828\n",
      "election                                                GR2022_Oss\n",
      "electionName                                 Gemeenteraad Oss 2022\n",
      "geometry                                               POINT (0 0)\n",
      "Name: 7913, Length: 973, dtype: object\n",
      "Stembureau                                                    1528\n",
      "Adres                                                             \n",
      "Locatie                                                     SB1528\n",
      "description        Stembureau Drive-thru parkeerplaats Rusheuvel 1\n",
      "Geldige stemmen                                                323\n",
      "                                        ...                       \n",
      "één-Ermelo                                                     NaN\n",
      "gmcode                                                      GM0828\n",
      "election                                                GR2022_Oss\n",
      "electionName                                 Gemeenteraad Oss 2022\n",
      "geometry                                               POINT (0 0)\n",
      "Name: 7923, Length: 973, dtype: object\n",
      "Stembureau                                                    1537\n",
      "Adres                                                             \n",
      "Locatie                                                     SB1537\n",
      "description        Stembureau Drive-thru parkeerplaats Rusheuvel 2\n",
      "Geldige stemmen                                                208\n",
      "                                        ...                       \n",
      "één-Ermelo                                                     NaN\n",
      "gmcode                                                      GM0828\n",
      "election                                                GR2022_Oss\n",
      "electionName                                 Gemeenteraad Oss 2022\n",
      "geometry                                               POINT (0 0)\n",
      "Name: 7924, Length: 973, dtype: object\n",
      "Stembureau                                 1541\n",
      "Adres                                          \n",
      "Locatie                                  SB1541\n",
      "description        Stembureau Mobiel stembureau\n",
      "Geldige stemmen                             125\n",
      "                               ...             \n",
      "één-Ermelo                                  NaN\n",
      "gmcode                                   GM0828\n",
      "election                             GR2022_Oss\n",
      "electionName              Gemeenteraad Oss 2022\n",
      "geometry                            POINT (0 0)\n",
      "Name: 7926, Length: 973, dtype: object\n",
      "Stembureau                                         200\n",
      "Adres                                                 \n",
      "Locatie                                          SB200\n",
      "description            Stembureau Mobiel stembureau Ma\n",
      "Geldige stemmen                                     30\n",
      "                                  ...                 \n",
      "één-Ermelo                                         NaN\n",
      "gmcode                                          GM1509\n",
      "election                       GR2022_OudeIJsselstreek\n",
      "electionName       Gemeenteraad Oude IJsselstreek 2022\n",
      "geometry                                   POINT (0 0)\n",
      "Name: 7958, Length: 973, dtype: object\n",
      "Stembureau                                         201\n",
      "Adres                                                 \n",
      "Locatie                                          SB201\n",
      "description            Stembureau Mobiel stembureau Di\n",
      "Geldige stemmen                                     30\n",
      "                                  ...                 \n",
      "één-Ermelo                                         NaN\n",
      "gmcode                                          GM1509\n",
      "election                       GR2022_OudeIJsselstreek\n",
      "electionName       Gemeenteraad Oude IJsselstreek 2022\n",
      "geometry                                   POINT (0 0)\n",
      "Name: 7959, Length: 973, dtype: object\n",
      "Stembureau                                         202\n",
      "Adres                                                 \n",
      "Locatie                                          SB202\n",
      "description           Stembureau Mobiel stembureau Woe\n",
      "Geldige stemmen                                     44\n",
      "                                  ...                 \n",
      "één-Ermelo                                         NaN\n",
      "gmcode                                          GM1509\n",
      "election                       GR2022_OudeIJsselstreek\n",
      "electionName       Gemeenteraad Oude IJsselstreek 2022\n",
      "geometry                                   POINT (0 0)\n",
      "Name: 7960, Length: 973, dtype: object\n",
      "Stembureau                                                        30\n",
      "Adres                                                               \n",
      "Locatie                                                         SB30\n",
      "description        Stembureau Stembureau voor de telling stembure...\n",
      "Geldige stemmen                                                 2004\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM1926\n",
      "election                                    GR2022_PijnackerNootdorp\n",
      "electionName                    Gemeenteraad Pijnacker-Nootdorp 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 8108, Length: 973, dtype: object\n",
      "Stembureau                                                        40\n",
      "Adres                                                               \n",
      "Locatie                                                         SB40\n",
      "description        Stembureau Stembureau voor de telling stembure...\n",
      "Geldige stemmen                                                 2953\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM1926\n",
      "election                                    GR2022_PijnackerNootdorp\n",
      "electionName                    Gemeenteraad Pijnacker-Nootdorp 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 8109, Length: 973, dtype: object\n",
      "Stembureau                                                      990\n",
      "Adres                                                              \n",
      "Locatie                                                       SB990\n",
      "description        Stembureau Mobiel stembureau (meerdere plaatsen)\n",
      "Geldige stemmen                                                  47\n",
      "                                         ...                       \n",
      "één-Ermelo                                                      NaN\n",
      "gmcode                                                       GM0177\n",
      "election                                              GR2022_Raalte\n",
      "electionName                               Gemeenteraad Raalte 2022\n",
      "geometry                                                POINT (0 0)\n",
      "Name: 8161, Length: 973, dtype: object\n",
      "Stembureau                                                      991\n",
      "Adres                                                              \n",
      "Locatie                                                       SB991\n",
      "description        Stembureau Mobiel stembureau (meerdere plaatsen)\n",
      "Geldige stemmen                                                  70\n",
      "                                         ...                       \n",
      "één-Ermelo                                                      NaN\n",
      "gmcode                                                       GM0177\n",
      "election                                              GR2022_Raalte\n",
      "electionName                               Gemeenteraad Raalte 2022\n",
      "geometry                                                POINT (0 0)\n",
      "Name: 8162, Length: 973, dtype: object\n",
      "Stembureau                                                      992\n",
      "Adres                                                              \n",
      "Locatie                                                       SB992\n",
      "description        Stembureau Mobiel stembureau (meerdere plaatsen)\n",
      "Geldige stemmen                                                  39\n",
      "                                         ...                       \n",
      "één-Ermelo                                                      NaN\n",
      "gmcode                                                       GM0177\n",
      "election                                              GR2022_Raalte\n",
      "electionName                               Gemeenteraad Raalte 2022\n",
      "geometry                                                POINT (0 0)\n",
      "Name: 8163, Length: 973, dtype: object\n",
      "Stembureau                                           17\n",
      "Adres                                                  \n",
      "Locatie                                            SB17\n",
      "description        Stembureau Mobiel Stembureau dinsdag\n",
      "Geldige stemmen                                     115\n",
      "                                   ...                 \n",
      "één-Ermelo                                          NaN\n",
      "gmcode                                           GM1742\n",
      "election                           GR2022_RijssenHolten\n",
      "electionName           Gemeenteraad Rijssen-Holten 2022\n",
      "geometry                                    POINT (0 0)\n",
      "Name: 8318, Length: 973, dtype: object\n",
      "Stembureau                                    228\n",
      "Adres                                            \n",
      "Locatie                                     SB228\n",
      "description        Stembureau Stembureau Drive-in\n",
      "Geldige stemmen                                80\n",
      "                                ...              \n",
      "één-Ermelo                                    NaN\n",
      "gmcode                                     GM0606\n",
      "election                          GR2022_Schiedam\n",
      "electionName           Gemeenteraad Schiedam 2022\n",
      "geometry                              POINT (0 0)\n",
      "Name: 9093, Length: 973, dtype: object\n",
      "Stembureau                                           30\n",
      "Adres                                                  \n",
      "Locatie                                            SB30\n",
      "description                Stembureau Mobiel stembureau\n",
      "Geldige stemmen                                      25\n",
      "                                   ...                 \n",
      "één-Ermelo                                          NaN\n",
      "gmcode                                           GM1676\n",
      "election                       GR2022_SchouwenDuiveland\n",
      "electionName       Gemeenteraad Schouwen-Duiveland 2022\n",
      "geometry                                    POINT (0 0)\n",
      "Name: 9151, Length: 973, dtype: object\n",
      "Stembureau                                           31\n",
      "Adres                                                  \n",
      "Locatie                                            SB31\n",
      "description                Stembureau Mobiel stembureau\n",
      "Geldige stemmen                                       8\n",
      "                                   ...                 \n",
      "één-Ermelo                                          NaN\n",
      "gmcode                                           GM1676\n",
      "election                       GR2022_SchouwenDuiveland\n",
      "electionName       Gemeenteraad Schouwen-Duiveland 2022\n",
      "geometry                                    POINT (0 0)\n",
      "Name: 9152, Length: 973, dtype: object\n",
      "Stembureau                                           32\n",
      "Adres                                                  \n",
      "Locatie                                            SB32\n",
      "description                Stembureau Mobiel stembureau\n",
      "Geldige stemmen                                      24\n",
      "                                   ...                 \n",
      "één-Ermelo                                          NaN\n",
      "gmcode                                           GM1676\n",
      "election                       GR2022_SchouwenDuiveland\n",
      "electionName       Gemeenteraad Schouwen-Duiveland 2022\n",
      "geometry                                    POINT (0 0)\n",
      "Name: 9153, Length: 973, dtype: object\n",
      "Stembureau                                          76\n",
      "Adres                                                 \n",
      "Locatie                                           SB76\n",
      "description        Stembureau Rondvaartboot Toerist VI\n",
      "Geldige stemmen                                    148\n",
      "                                  ...                 \n",
      "één-Ermelo                                         NaN\n",
      "gmcode                                          GM1900\n",
      "election                         GR2022_SudwestFryslan\n",
      "electionName         Gemeenteraad Súdwest-Fryslân 2022\n",
      "geometry                                   POINT (0 0)\n",
      "Name: 9661, Length: 973, dtype: object\n",
      "Stembureau                                                        68\n",
      "Adres                                                               \n",
      "Locatie                                                         SB68\n",
      "description        Stembureau Drive Inn (evenemententerrein Het L...\n",
      "Geldige stemmen                                                  285\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0855\n",
      "election                                              GR2022_Tilburg\n",
      "electionName                               Gemeenteraad Tilburg 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 9853, Length: 973, dtype: object\n",
      "Stembureau                                   14\n",
      "Adres                                          \n",
      "Locatie                                    SB14\n",
      "description        Stembureau Mobiel Stembureau\n",
      "Geldige stemmen                              24\n",
      "                               ...             \n",
      "één-Ermelo                                  NaN\n",
      "gmcode                                   GM0047\n",
      "election                         GR2022_Veendam\n",
      "electionName          Gemeenteraad Veendam 2022\n",
      "geometry                            POINT (0 0)\n",
      "Name: 10427, Length: 973, dtype: object\n",
      "Stembureau                                   18\n",
      "Adres                                          \n",
      "Locatie                                    SB18\n",
      "description        Stembureau Mobiel stembureau\n",
      "Geldige stemmen                              50\n",
      "                               ...             \n",
      "één-Ermelo                                  NaN\n",
      "gmcode                                   GM0047\n",
      "election                         GR2022_Veendam\n",
      "electionName          Gemeenteraad Veendam 2022\n",
      "geometry                            POINT (0 0)\n",
      "Name: 10431, Length: 973, dtype: object\n",
      "Stembureau                                                   23\n",
      "Adres                                                          \n",
      "Locatie                                                    SB23\n",
      "description        Stembureau Stembureau Mobiel: Wkp Zout Veere\n",
      "Geldige stemmen                                              55\n",
      "                                       ...                     \n",
      "één-Ermelo                                                  NaN\n",
      "gmcode                                                   GM0717\n",
      "election                                           GR2022_Veere\n",
      "electionName                            Gemeenteraad Veere 2022\n",
      "geometry                                            POINT (0 0)\n",
      "Name: 10497, Length: 973, dtype: object\n",
      "Stembureau                                            24\n",
      "Adres                                                   \n",
      "Locatie                                             SB24\n",
      "description        Stembureau Stembureau Mobiel: Okp Dom\n",
      "Geldige stemmen                                       35\n",
      "                                   ...                  \n",
      "één-Ermelo                                           NaN\n",
      "gmcode                                            GM0717\n",
      "election                                    GR2022_Veere\n",
      "electionName                     Gemeenteraad Veere 2022\n",
      "geometry                                     POINT (0 0)\n",
      "Name: 10498, Length: 973, dtype: object\n",
      "Stembureau                                     115\n",
      "Adres                                             \n",
      "Locatie                                      SB115\n",
      "description        Stembureau Tent Nijverheidslaan\n",
      "Geldige stemmen                                258\n",
      "                                ...               \n",
      "één-Ermelo                                     NaN\n",
      "gmcode                                      GM0861\n",
      "election                          GR2022_Veldhoven\n",
      "electionName           Gemeenteraad Veldhoven 2022\n",
      "geometry                               POINT (0 0)\n",
      "Name: 10525, Length: 973, dtype: object\n",
      "Stembureau                                     116\n",
      "Adres                                             \n",
      "Locatie                                      SB116\n",
      "description        Stembureau Tent Nijverheidslaan\n",
      "Geldige stemmen                                377\n",
      "                                ...               \n",
      "één-Ermelo                                     NaN\n",
      "gmcode                                      GM0861\n",
      "election                          GR2022_Veldhoven\n",
      "electionName           Gemeenteraad Veldhoven 2022\n",
      "geometry                               POINT (0 0)\n",
      "Name: 10526, Length: 973, dtype: object\n",
      "Stembureau                                         117\n",
      "Adres                                                 \n",
      "Locatie                                          SB117\n",
      "description        Stembureau Tent Peter Benenson park\n",
      "Geldige stemmen                                    285\n",
      "                                  ...                 \n",
      "één-Ermelo                                         NaN\n",
      "gmcode                                          GM0861\n",
      "election                              GR2022_Veldhoven\n",
      "electionName               Gemeenteraad Veldhoven 2022\n",
      "geometry                                   POINT (0 0)\n",
      "Name: 10527, Length: 973, dtype: object\n",
      "Stembureau                                         118\n",
      "Adres                                                 \n",
      "Locatie                                          SB118\n",
      "description        Stembureau Tent Peter Benenson park\n",
      "Geldige stemmen                                    329\n",
      "                                  ...                 \n",
      "één-Ermelo                                         NaN\n",
      "gmcode                                          GM0861\n",
      "election                              GR2022_Veldhoven\n",
      "electionName               Gemeenteraad Veldhoven 2022\n",
      "geometry                                   POINT (0 0)\n",
      "Name: 10528, Length: 973, dtype: object\n",
      "Stembureau                                              310\n",
      "Adres                                                      \n",
      "Locatie                                               SB310\n",
      "description        Stembureau Mobiel Bijzonder stembureau 1\n",
      "Geldige stemmen                                          26\n",
      "                                     ...                   \n",
      "één-Ermelo                                              NaN\n",
      "gmcode                                               GM0983\n",
      "election                                       GR2022_Venlo\n",
      "electionName                        Gemeenteraad Venlo 2022\n",
      "geometry                                        POINT (0 0)\n",
      "Name: 10623, Length: 973, dtype: object\n",
      "Stembureau                                              311\n",
      "Adres                                                      \n",
      "Locatie                                               SB311\n",
      "description        Stembureau Mobiel Bijzonder stembureau 2\n",
      "Geldige stemmen                                          55\n",
      "                                     ...                   \n",
      "één-Ermelo                                              NaN\n",
      "gmcode                                               GM0983\n",
      "election                                       GR2022_Venlo\n",
      "electionName                        Gemeenteraad Venlo 2022\n",
      "geometry                                        POINT (0 0)\n",
      "Name: 10624, Length: 973, dtype: object\n",
      "Stembureau                                     88\n",
      "Adres                                            \n",
      "Locatie                                      SB88\n",
      "description        Stembureau Mobiel stembureau 1\n",
      "Geldige stemmen                                78\n",
      "                                ...              \n",
      "één-Ermelo                                    NaN\n",
      "gmcode                                     GM1949\n",
      "election                         GR2022_Waadhoeke\n",
      "electionName          Gemeenteraad Waadhoeke 2022\n",
      "geometry                              POINT (0 0)\n",
      "Name: 10894, Length: 973, dtype: object\n",
      "Stembureau                                     89\n",
      "Adres                                            \n",
      "Locatie                                      SB89\n",
      "description        Stembureau Mobiel stembureau 2\n",
      "Geldige stemmen                                35\n",
      "                                ...              \n",
      "één-Ermelo                                    NaN\n",
      "gmcode                                     GM1949\n",
      "election                         GR2022_Waadhoeke\n",
      "electionName          Gemeenteraad Waadhoeke 2022\n",
      "geometry                              POINT (0 0)\n",
      "Name: 10895, Length: 973, dtype: object\n",
      "Stembureau                                              31\n",
      "Adres                                                     \n",
      "Locatie                                               SB31\n",
      "description        Stembureau Stembureau Mobiel Stembureau\n",
      "Geldige stemmen                                         32\n",
      "                                    ...                   \n",
      "één-Ermelo                                             NaN\n",
      "gmcode                                              GM0988\n",
      "election                                      GR2022_Weert\n",
      "electionName                       Gemeenteraad Weert 2022\n",
      "geometry                                       POINT (0 0)\n",
      "Name: 11032, Length: 973, dtype: object\n",
      "Stembureau                                     0\n",
      "Adres                                           \n",
      "Locatie                                      SB0\n",
      "description                         Stembureau -\n",
      "Geldige stemmen                                0\n",
      "                               ...              \n",
      "één-Ermelo                                   NaN\n",
      "gmcode                                    GM1960\n",
      "election                       GR2022_WestBetuwe\n",
      "electionName       Gemeenteraad West Betuwe 2022\n",
      "geometry                             POINT (0 0)\n",
      "Name: 11101, Length: 973, dtype: object\n",
      "Stembureau                                                       132\n",
      "Adres                                                               \n",
      "Locatie                                                        SB132\n",
      "description        Stembureau Stembureau IJsselhallen drive thoug...\n",
      "Geldige stemmen                                                   52\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0193\n",
      "election                                               GR2022_Zwolle\n",
      "electionName                                Gemeenteraad Zwolle 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 12038, Length: 973, dtype: object\n",
      "Stembureau                                                       133\n",
      "Adres                                                               \n",
      "Locatie                                                        SB133\n",
      "description        Stembureau Stembureau IJsselhallen drive throu...\n",
      "Geldige stemmen                                                   48\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0193\n",
      "election                                               GR2022_Zwolle\n",
      "electionName                                Gemeenteraad Zwolle 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 12039, Length: 973, dtype: object\n",
      "Stembureau                                                       232\n",
      "Adres                                                               \n",
      "Locatie                                                        SB232\n",
      "description        Stembureau Stembureau IJsselhallen drive thoug...\n",
      "Geldige stemmen                                                  113\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0193\n",
      "election                                               GR2022_Zwolle\n",
      "electionName                                Gemeenteraad Zwolle 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 12053, Length: 973, dtype: object\n",
      "Stembureau                                                       233\n",
      "Adres                                                               \n",
      "Locatie                                                        SB233\n",
      "description        Stembureau Stembureau IJsselhallen drive throu...\n",
      "Geldige stemmen                                                   73\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0193\n",
      "election                                               GR2022_Zwolle\n",
      "electionName                                Gemeenteraad Zwolle 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 12054, Length: 973, dtype: object\n",
      "Stembureau                                               358\n",
      "Adres                                                       \n",
      "Locatie                                                SB358\n",
      "description        Stembureau Stembureau Mobiel stembureau 1\n",
      "Geldige stemmen                                           70\n",
      "                                     ...                    \n",
      "één-Ermelo                                               NaN\n",
      "gmcode                                                GM0193\n",
      "election                                       GR2022_Zwolle\n",
      "electionName                        Gemeenteraad Zwolle 2022\n",
      "geometry                                         POINT (0 0)\n",
      "Name: 12118, Length: 973, dtype: object\n",
      "Stembureau                                               359\n",
      "Adres                                                       \n",
      "Locatie                                                SB359\n",
      "description        Stembureau Stembureau Mobiel stembureau 2\n",
      "Geldige stemmen                                          169\n",
      "                                     ...                    \n",
      "één-Ermelo                                               NaN\n",
      "gmcode                                                GM0193\n",
      "election                                       GR2022_Zwolle\n",
      "electionName                        Gemeenteraad Zwolle 2022\n",
      "geometry                                         POINT (0 0)\n",
      "Name: 12119, Length: 973, dtype: object\n",
      "Stembureau                                               360\n",
      "Adres                                                       \n",
      "Locatie                                                SB360\n",
      "description        Stembureau Stembureau Mobiel stembureau 3\n",
      "Geldige stemmen                                           89\n",
      "                                     ...                    \n",
      "één-Ermelo                                               NaN\n",
      "gmcode                                                GM0193\n",
      "election                                       GR2022_Zwolle\n",
      "electionName                        Gemeenteraad Zwolle 2022\n",
      "geometry                                         POINT (0 0)\n",
      "Name: 12120, Length: 973, dtype: object\n",
      "Stembureau                                               361\n",
      "Adres                                                       \n",
      "Locatie                                                SB361\n",
      "description        Stembureau Stembureau Mobiel stembureau 4\n",
      "Geldige stemmen                                           36\n",
      "                                     ...                    \n",
      "één-Ermelo                                               NaN\n",
      "gmcode                                                GM0193\n",
      "election                                       GR2022_Zwolle\n",
      "electionName                        Gemeenteraad Zwolle 2022\n",
      "geometry                                         POINT (0 0)\n",
      "Name: 12121, Length: 973, dtype: object\n",
      "Stembureau                                                       114\n",
      "Adres                                                               \n",
      "Locatie                                                        SB114\n",
      "description        Stembureau Stembureau Mobiel stembureau (beper...\n",
      "Geldige stemmen                                                  109\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0796\n",
      "election                                       GR2022_sHertogenbosch\n",
      "electionName                      Gemeenteraad 's-Hertogenbosch 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 12504, Length: 973, dtype: object\n",
      "Stembureau                                                       115\n",
      "Adres                                                               \n",
      "Locatie                                                        SB115\n",
      "description        Stembureau Stembureau Mobiel Stembureau (beper...\n",
      "Geldige stemmen                                                   80\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0796\n",
      "election                                       GR2022_sHertogenbosch\n",
      "electionName                      Gemeenteraad 's-Hertogenbosch 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 12505, Length: 973, dtype: object\n",
      "Stembureau                                                       116\n",
      "Adres                                                               \n",
      "Locatie                                                        SB116\n",
      "description        Stembureau Stembureau Mobiel Stembureau (beper...\n",
      "Geldige stemmen                                                  119\n",
      "                                         ...                        \n",
      "één-Ermelo                                                       NaN\n",
      "gmcode                                                        GM0796\n",
      "election                                       GR2022_sHertogenbosch\n",
      "electionName                      Gemeenteraad 's-Hertogenbosch 2022\n",
      "geometry                                                 POINT (0 0)\n",
      "Name: 12506, Length: 973, dtype: object\n"
     ]
    }
   ],
   "source": [
    "for index, row in df_geojson.iterrows():\n",
    "    if (row.geometry.centroid.x == 0.00000):\n",
    "        print(row)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "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."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2520\n",
      "2521\n",
      "2918\n",
      "3579\n",
      "3580\n",
      "3581\n",
      "3582\n",
      "3583\n",
      "5494\n",
      "5784\n",
      "5785\n",
      "6260\n",
      "6261\n",
      "6738\n",
      "6739\n",
      "6863\n",
      "7348\n",
      "7364\n",
      "7857\n",
      "7912\n",
      "7913\n",
      "7923\n",
      "7924\n",
      "7926\n",
      "7958\n",
      "7959\n",
      "7960\n",
      "8108\n",
      "8109\n",
      "8161\n",
      "8162\n",
      "8163\n",
      "8318\n",
      "9093\n",
      "9151\n",
      "9152\n",
      "9153\n",
      "9661\n",
      "9853\n",
      "10427\n",
      "10431\n",
      "10497\n",
      "10498\n",
      "10525\n",
      "10526\n",
      "10527\n",
      "10528\n",
      "10623\n",
      "10624\n",
      "10894\n",
      "10895\n",
      "11032\n",
      "11101\n",
      "12038\n",
      "12039\n",
      "12053\n",
      "12054\n",
      "12118\n",
      "12119\n",
      "12120\n",
      "12121\n",
      "12504\n",
      "12505\n",
      "12506\n"
     ]
    }
   ],
   "source": [
    "# De waarschuwing over de projectie die niet klopt kan genegeerd worden, we zoeken naar data die x = 0 is,\n",
    "# de projectie gaat geen effect hebben op die data in Nederland.\n",
    "\n",
    "# Filter de data en print welke waardes 0 hebben op x.\n",
    "mobiel_mask = df_geojson['geometry'].centroid.x == 0\n",
    "i = 0\n",
    "for item in mobiel_mask:\n",
    "    if item:\n",
    "        print(i)\n",
    "    i = i + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       Stembureau   Adres Locatie  \\\n",
      "0               1  9461BH     SB1   \n",
      "1               2  9461DA     SB2   \n",
      "2               3  9461JA     SB3   \n",
      "3               4  9451KD     SB4   \n",
      "4               6  9454PL     SB6   \n",
      "...           ...     ...     ...   \n",
      "12591         703  5391AR   SB703   \n",
      "12592         705  5391AR   SB705   \n",
      "12593         750  5382KE   SB750   \n",
      "12594         751  5382KE   SB751   \n",
      "12595         752  5283KE   SB752   \n",
      "\n",
      "                                             description  Geldige stemmen  \\\n",
      "0      Stembureau Gemeentehuis Gieten (postcode: 9461...              784   \n",
      "1              Stembureau OBS Gieten (postcode: 9461 DA)              562   \n",
      "2      Stembureau Zorgcentrum Dekelhem (postcode: 946...              566   \n",
      "3      Stembureau Ontmoetingscentrum Boerhorn Rolde (...             1495   \n",
      "4      Stembureau Dropshuis de Eekhof (postcode: 9454...              347   \n",
      "...                                                  ...              ...   \n",
      "12591  Stembureau Stembureau Gemeenschapshuis de Meen...              268   \n",
      "12592  Stembureau Stembureau Gemeenschapshuis De Meen...              398   \n",
      "12593  Stembureau Stembureau Gemeenschapshuis 't Zijl...              663   \n",
      "12594  Stembureau Stembureau Gemeenschapshuis 't Zijl...              170   \n",
      "12595  Stembureau Stembureau Gemeenschapshuis 't Zijl...              222   \n",
      "\n",
      "       Opgeroepen  Ongeldig  Blanco  Geldige stempassen  \\\n",
      "0            2780         3       3                 700   \n",
      "1            1396         0       0                 518   \n",
      "2            1409         2       2                 516   \n",
      "3            2209         2       4                1335   \n",
      "4             477         0       2                 298   \n",
      "...           ...       ...     ...                 ...   \n",
      "12591           0         0       1                 237   \n",
      "12592           0         1       0                 359   \n",
      "12593        2321         2       0                 552   \n",
      "12594           0         0       0                 151   \n",
      "12595           0         0       0                 193   \n",
      "\n",
      "       Geldige volmachtbewijzen  ...  Partij voor Logisch Beleid (PvLB)  \\\n",
      "0                            90  ...                                NaN   \n",
      "1                            44  ...                                NaN   \n",
      "2                            54  ...                                NaN   \n",
      "3                           166  ...                                NaN   \n",
      "4                            51  ...                                NaN   \n",
      "...                         ...  ...                                ...   \n",
      "12591                        32  ...                                NaN   \n",
      "12592                        40  ...                                NaN   \n",
      "12593                       113  ...                                NaN   \n",
      "12594                        19  ...                                NaN   \n",
      "12595                        29  ...                                NaN   \n",
      "\n",
      "       Socialisten 010  Jong Rotterdam  VOOR Den Bosch Joep Gersjes  \\\n",
      "0                  NaN             NaN                          NaN   \n",
      "1                  NaN             NaN                          NaN   \n",
      "2                  NaN             NaN                          NaN   \n",
      "3                  NaN             NaN                          NaN   \n",
      "4                  NaN             NaN                          NaN   \n",
      "...                ...             ...                          ...   \n",
      "12591              NaN             NaN                          0.0   \n",
      "12592              NaN             NaN                          2.0   \n",
      "12593              NaN             NaN                          5.0   \n",
      "12594              NaN             NaN                          1.0   \n",
      "12595              NaN             NaN                          0.0   \n",
      "\n",
      "       Zorg Voor Gorkum  één-Ermelo  gmcode               election  \\\n",
      "0                   NaN         NaN  GM1680       GR2022_AaenHunze   \n",
      "1                   NaN         NaN  GM1680       GR2022_AaenHunze   \n",
      "2                   NaN         NaN  GM1680       GR2022_AaenHunze   \n",
      "3                   NaN         NaN  GM1680       GR2022_AaenHunze   \n",
      "4                   NaN         NaN  GM1680       GR2022_AaenHunze   \n",
      "...                 ...         ...     ...                    ...   \n",
      "12591               NaN         NaN  GM0796  GR2022_sHertogenbosch   \n",
      "12592               NaN         NaN  GM0796  GR2022_sHertogenbosch   \n",
      "12593               NaN         NaN  GM0796  GR2022_sHertogenbosch   \n",
      "12594               NaN         NaN  GM0796  GR2022_sHertogenbosch   \n",
      "12595               NaN         NaN  GM0796  GR2022_sHertogenbosch   \n",
      "\n",
      "                             electionName                  geometry  \n",
      "0           Gemeenteraad Aa en Hunze 2022  POINT (6.75899 53.00524)  \n",
      "1           Gemeenteraad Aa en Hunze 2022  POINT (6.75990 52.99975)  \n",
      "2           Gemeenteraad Aa en Hunze 2022  POINT (6.76600 53.00494)  \n",
      "3           Gemeenteraad Aa en Hunze 2022  POINT (6.64736 52.98281)  \n",
      "4           Gemeenteraad Aa en Hunze 2022  POINT (6.60459 52.95269)  \n",
      "...                                   ...                       ...  \n",
      "12591  Gemeenteraad 's-Hertogenbosch 2022  POINT (5.43290 51.72810)  \n",
      "12592  Gemeenteraad 's-Hertogenbosch 2022  POINT (5.43290 51.72810)  \n",
      "12593  Gemeenteraad 's-Hertogenbosch 2022  POINT (5.45919 51.70595)  \n",
      "12594  Gemeenteraad 's-Hertogenbosch 2022  POINT (5.45919 51.70595)  \n",
      "12595  Gemeenteraad 's-Hertogenbosch 2022  POINT (5.45919 51.70595)  \n",
      "\n",
      "[12532 rows x 973 columns]\n"
     ]
    }
   ],
   "source": [
    "df_geojson_clean = df_geojson[~mobiel_mask]\n",
    "df_geojson_mobiel = df_geojson[mobiel_mask]\n",
    "print(df_geojson_clean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Let's also check if none fell through the cracks, it might be some mobile polls did actually have a location\n",
    "# posted erroneously\n",
    "#mobiel_mask_name = df_geojson_clean['description'].str.contains('Mobiel')\n",
    "#df_geojson_clean = df_geojson_clean[~mobiel_mask_name]\n",
    "#df_geojson_clean"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 'Waar is mijn stemlokaal' dataset (wims)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>_id</th>\n",
       "      <th>Gemeente</th>\n",
       "      <th>CBS gemeentecode</th>\n",
       "      <th>Nummer stembureau</th>\n",
       "      <th>Naam stembureau</th>\n",
       "      <th>Gebruiksdoel van het gebouw</th>\n",
       "      <th>Website locatie</th>\n",
       "      <th>Wijknaam</th>\n",
       "      <th>CBS wijknummer</th>\n",
       "      <th>...</th>\n",
       "      <th>Visuele hulpmiddelen</th>\n",
       "      <th>Gehandicaptentoilet</th>\n",
       "      <th>Kieskring ID</th>\n",
       "      <th>Hoofdstembureau</th>\n",
       "      <th>Tellocatie</th>\n",
       "      <th>Contactgegevens gemeente</th>\n",
       "      <th>Verkiezingswebsite gemeente</th>\n",
       "      <th>Verkiezingen</th>\n",
       "      <th>ID</th>\n",
       "      <th>UUID</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>1</td>\n",
       "      <td>Zorgcentrum Kempenhof</td>\n",
       "      <td>gezondheidszorgfunctie</td>\n",
       "      <td>https://www.valkenhof.nl/</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>leesloep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>3a612b2151fa4ab491b9e331355e6258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>2</td>\n",
       "      <td>Buurtgebouw De Horizon</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>leesloep</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>9a01d765af0a467ea37f08d92db114ba</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>3</td>\n",
       "      <td>Speeltuin Geenhoven</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>leesloep</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>fc5869d33fbc4b06be659149fa615f4c</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>4</td>\n",
       "      <td>Ontmoetingscentrum De zoete inval</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>leesloep</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>4427cc0b39e040ba8f75c333f19d66f0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>5</td>\n",
       "      <td>Gymnastiekzaal 't Gegraaf</td>\n",
       "      <td>sportfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>leesloep</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>a893bb9add324ce29769f1c39afcc48d</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9270</th>\n",
       "      <td>9270</td>\n",
       "      <td>38745</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>4</td>\n",
       "      <td>Het Hökske</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>Leesloep</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>f744546cd6894e5e9a4db4bbfd81b4ee</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9271</th>\n",
       "      <td>9271</td>\n",
       "      <td>38746</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>5</td>\n",
       "      <td>Buurthuis VanOns</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>Leesloep</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>1270081b1dc74cd7bea0f45973650408</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9272</th>\n",
       "      <td>9272</td>\n",
       "      <td>38747</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>6</td>\n",
       "      <td>'t Trefpunt</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>Leesloep</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>447c7742604345139e41def4cf1e4d3c</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9273</th>\n",
       "      <td>9273</td>\n",
       "      <td>38748</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>8</td>\n",
       "      <td>De Uitkomst</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>Leesloep</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>049cfd258c174bc49abf17883396d083</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9274</th>\n",
       "      <td>9274</td>\n",
       "      <td>38749</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>1</td>\n",
       "      <td>Zaal Buurman</td>\n",
       "      <td>woonfunctie,bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>1e8cbe96e72c4c6ba6303f47bec8cdb5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9275 rows × 40 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Unnamed: 0    _id      Gemeente CBS gemeentecode  Nummer stembureau  \\\n",
       "0              0      1  Valkenswaard           GM0858                  1   \n",
       "1              1      2  Valkenswaard           GM0858                  2   \n",
       "2              2      3  Valkenswaard           GM0858                  3   \n",
       "3              3      4  Valkenswaard           GM0858                  4   \n",
       "4              4      5  Valkenswaard           GM0858                  5   \n",
       "...          ...    ...           ...              ...                ...   \n",
       "9270        9270  38745        Gennep           GM0907                  4   \n",
       "9271        9271  38746        Gennep           GM0907                  5   \n",
       "9272        9272  38747        Gennep           GM0907                  6   \n",
       "9273        9273  38748        Gennep           GM0907                  8   \n",
       "9274        9274  38749        Gennep           GM0907                  1   \n",
       "\n",
       "                        Naam stembureau     Gebruiksdoel van het gebouw  \\\n",
       "0                 Zorgcentrum Kempenhof          gezondheidszorgfunctie   \n",
       "1                Buurtgebouw De Horizon              bijeenkomstfunctie   \n",
       "2                   Speeltuin Geenhoven              bijeenkomstfunctie   \n",
       "3     Ontmoetingscentrum De zoete inval              bijeenkomstfunctie   \n",
       "4             Gymnastiekzaal 't Gegraaf                    sportfunctie   \n",
       "...                                 ...                             ...   \n",
       "9270                         Het Hökske              bijeenkomstfunctie   \n",
       "9271                   Buurthuis VanOns              bijeenkomstfunctie   \n",
       "9272                        't Trefpunt              bijeenkomstfunctie   \n",
       "9273                        De Uitkomst              bijeenkomstfunctie   \n",
       "9274                       Zaal Buurman  woonfunctie,bijeenkomstfunctie   \n",
       "\n",
       "                Website locatie  Wijknaam  CBS wijknummer  ...  \\\n",
       "0     https://www.valkenhof.nl/       NaN             NaN  ...   \n",
       "1                           NaN       NaN             NaN  ...   \n",
       "2                           NaN       NaN             NaN  ...   \n",
       "3                           NaN       NaN             NaN  ...   \n",
       "4                           NaN       NaN             NaN  ...   \n",
       "...                         ...       ...             ...  ...   \n",
       "9270                        NaN       NaN             NaN  ...   \n",
       "9271                        NaN       NaN             NaN  ...   \n",
       "9272                        NaN       NaN             NaN  ...   \n",
       "9273                        NaN       NaN             NaN  ...   \n",
       "9274                        NaN       NaN             NaN  ...   \n",
       "\n",
       "      Visuele hulpmiddelen  Gehandicaptentoilet  Kieskring ID Hoofdstembureau  \\\n",
       "0                 leesloep                   ja  Valkenswaard    Valkenswaard   \n",
       "1                 leesloep                  NaN  Valkenswaard    Valkenswaard   \n",
       "2                 leesloep                  NaN  Valkenswaard    Valkenswaard   \n",
       "3                 leesloep                  NaN  Valkenswaard    Valkenswaard   \n",
       "4                 leesloep                  NaN  Valkenswaard    Valkenswaard   \n",
       "...                    ...                  ...           ...             ...   \n",
       "9270              Leesloep                  NaN        Gennep          Gennep   \n",
       "9271              Leesloep                  NaN        Gennep          Gennep   \n",
       "9272              Leesloep                  NaN        Gennep          Gennep   \n",
       "9273              Leesloep                  NaN        Gennep          Gennep   \n",
       "9274                   NaN                  NaN        Gennep          Gennep   \n",
       "\n",
       "      Tellocatie                           Contactgegevens gemeente  \\\n",
       "0            NaN                       verkiezingen@valkenswaard.nl   \n",
       "1            NaN                       verkiezingen@valkenswaard.nl   \n",
       "2            NaN                       verkiezingen@valkenswaard.nl   \n",
       "3            NaN                       verkiezingen@valkenswaard.nl   \n",
       "4            NaN                       verkiezingen@valkenswaard.nl   \n",
       "...          ...                                                ...   \n",
       "9270          ja  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9271          ja  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9272          ja  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9273          ja  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9274         NaN  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "\n",
       "                  Verkiezingswebsite gemeente Verkiezingen  \\\n",
       "0     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "1     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "2     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "3     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "4     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "...                                       ...          ...   \n",
       "9270                    https://www.gennep.nl          NaN   \n",
       "9271                    https://www.gennep.nl          NaN   \n",
       "9272                    https://www.gennep.nl          NaN   \n",
       "9273                    https://www.gennep.nl          NaN   \n",
       "9274                    https://www.gennep.nl          NaN   \n",
       "\n",
       "                                     ID                              UUID  \n",
       "0     NLODSGM0858stembureaus20220316009  3a612b2151fa4ab491b9e331355e6258  \n",
       "1     NLODSGM0858stembureaus20220316009  9a01d765af0a467ea37f08d92db114ba  \n",
       "2     NLODSGM0858stembureaus20220316009  fc5869d33fbc4b06be659149fa615f4c  \n",
       "3     NLODSGM0858stembureaus20220316009  4427cc0b39e040ba8f75c333f19d66f0  \n",
       "4     NLODSGM0858stembureaus20220316009  a893bb9add324ce29769f1c39afcc48d  \n",
       "...                                 ...                               ...  \n",
       "9270  NLODSGM0907stembureaus20220316009  f744546cd6894e5e9a4db4bbfd81b4ee  \n",
       "9271  NLODSGM0907stembureaus20220316009  1270081b1dc74cd7bea0f45973650408  \n",
       "9272  NLODSGM0907stembureaus20220316009  447c7742604345139e41def4cf1e4d3c  \n",
       "9273  NLODSGM0907stembureaus20220316009  049cfd258c174bc49abf17883396d083  \n",
       "9274  NLODSGM0907stembureaus20220316009  1e8cbe96e72c4c6ba6303f47bec8cdb5  \n",
       "\n",
       "[9275 rows x 40 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_wims = pd.read_csv(r'../data/wims_clean.csv')\n",
    "df_wims"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_wims2 = pd.read_csv(r'../data/wims-3.csv')\n",
    "df_wims['Gebruiksdoel van het gebouw'] = df_wims['Gebruiksdoel van het gebouw'].mask(df_wims['Gebruiksdoel van het gebouw'].eq(0)).fillna(\n",
    "    df_wims['UUID'].map(df_wims2.set_index('UUID')['Gebruiksdoel van het gebouw'])\n",
    ")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_wims.to_csv(path_or_buf='../data/export/wims_clean.csv', sep=',', na_rep='', header=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>_id</th>\n",
       "      <th>Gemeente</th>\n",
       "      <th>CBS gemeentecode</th>\n",
       "      <th>Nummer stembureau</th>\n",
       "      <th>Naam stembureau</th>\n",
       "      <th>Gebruiksdoel van het gebouw</th>\n",
       "      <th>Website locatie</th>\n",
       "      <th>Wijknaam</th>\n",
       "      <th>CBS wijknummer</th>\n",
       "      <th>...</th>\n",
       "      <th>Gehandicaptentoilet</th>\n",
       "      <th>Kieskring ID</th>\n",
       "      <th>Hoofdstembureau</th>\n",
       "      <th>Tellocatie</th>\n",
       "      <th>Contactgegevens gemeente</th>\n",
       "      <th>Verkiezingswebsite gemeente</th>\n",
       "      <th>Verkiezingen</th>\n",
       "      <th>ID</th>\n",
       "      <th>UUID</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>1</td>\n",
       "      <td>Zorgcentrum Kempenhof</td>\n",
       "      <td>gezondheidszorgfunctie</td>\n",
       "      <td>https://www.valkenhof.nl/</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>ja</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>3a612b2151fa4ab491b9e331355e6258</td>\n",
       "      <td>POINT (5.45515 51.34711)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>2</td>\n",
       "      <td>Buurtgebouw De Horizon</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>9a01d765af0a467ea37f08d92db114ba</td>\n",
       "      <td>POINT (5.45137 51.34955)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>3</td>\n",
       "      <td>Speeltuin Geenhoven</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>fc5869d33fbc4b06be659149fa615f4c</td>\n",
       "      <td>POINT (5.44827 51.35702)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>4</td>\n",
       "      <td>Ontmoetingscentrum De zoete inval</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>4427cc0b39e040ba8f75c333f19d66f0</td>\n",
       "      <td>POINT (5.44871 51.36022)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>5</td>\n",
       "      <td>Gymnastiekzaal 't Gegraaf</td>\n",
       "      <td>sportfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>a893bb9add324ce29769f1c39afcc48d</td>\n",
       "      <td>POINT (5.45331 51.36514)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9270</th>\n",
       "      <td>9270</td>\n",
       "      <td>38745</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>4</td>\n",
       "      <td>Het Hökske</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>f744546cd6894e5e9a4db4bbfd81b4ee</td>\n",
       "      <td>POINT (5.98266 51.69726)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9271</th>\n",
       "      <td>9271</td>\n",
       "      <td>38746</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>5</td>\n",
       "      <td>Buurthuis VanOns</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>1270081b1dc74cd7bea0f45973650408</td>\n",
       "      <td>POINT (5.98127 51.69000)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9272</th>\n",
       "      <td>9272</td>\n",
       "      <td>38747</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>6</td>\n",
       "      <td>'t Trefpunt</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>447c7742604345139e41def4cf1e4d3c</td>\n",
       "      <td>POINT (5.95118 51.72591)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9273</th>\n",
       "      <td>9273</td>\n",
       "      <td>38748</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>8</td>\n",
       "      <td>De Uitkomst</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>049cfd258c174bc49abf17883396d083</td>\n",
       "      <td>POINT (6.01556 51.70976)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9274</th>\n",
       "      <td>9274</td>\n",
       "      <td>38749</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>1</td>\n",
       "      <td>Zaal Buurman</td>\n",
       "      <td>woonfunctie,bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>1e8cbe96e72c4c6ba6303f47bec8cdb5</td>\n",
       "      <td>POINT (5.98514 51.70189)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9275 rows × 41 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Unnamed: 0    _id      Gemeente CBS gemeentecode  Nummer stembureau  \\\n",
       "0              0      1  Valkenswaard           GM0858                  1   \n",
       "1              1      2  Valkenswaard           GM0858                  2   \n",
       "2              2      3  Valkenswaard           GM0858                  3   \n",
       "3              3      4  Valkenswaard           GM0858                  4   \n",
       "4              4      5  Valkenswaard           GM0858                  5   \n",
       "...          ...    ...           ...              ...                ...   \n",
       "9270        9270  38745        Gennep           GM0907                  4   \n",
       "9271        9271  38746        Gennep           GM0907                  5   \n",
       "9272        9272  38747        Gennep           GM0907                  6   \n",
       "9273        9273  38748        Gennep           GM0907                  8   \n",
       "9274        9274  38749        Gennep           GM0907                  1   \n",
       "\n",
       "                        Naam stembureau     Gebruiksdoel van het gebouw  \\\n",
       "0                 Zorgcentrum Kempenhof          gezondheidszorgfunctie   \n",
       "1                Buurtgebouw De Horizon              bijeenkomstfunctie   \n",
       "2                   Speeltuin Geenhoven              bijeenkomstfunctie   \n",
       "3     Ontmoetingscentrum De zoete inval              bijeenkomstfunctie   \n",
       "4             Gymnastiekzaal 't Gegraaf                    sportfunctie   \n",
       "...                                 ...                             ...   \n",
       "9270                         Het Hökske              bijeenkomstfunctie   \n",
       "9271                   Buurthuis VanOns              bijeenkomstfunctie   \n",
       "9272                        't Trefpunt              bijeenkomstfunctie   \n",
       "9273                        De Uitkomst              bijeenkomstfunctie   \n",
       "9274                       Zaal Buurman  woonfunctie,bijeenkomstfunctie   \n",
       "\n",
       "                Website locatie  Wijknaam  CBS wijknummer  ...  \\\n",
       "0     https://www.valkenhof.nl/       NaN             NaN  ...   \n",
       "1                           NaN       NaN             NaN  ...   \n",
       "2                           NaN       NaN             NaN  ...   \n",
       "3                           NaN       NaN             NaN  ...   \n",
       "4                           NaN       NaN             NaN  ...   \n",
       "...                         ...       ...             ...  ...   \n",
       "9270                        NaN       NaN             NaN  ...   \n",
       "9271                        NaN       NaN             NaN  ...   \n",
       "9272                        NaN       NaN             NaN  ...   \n",
       "9273                        NaN       NaN             NaN  ...   \n",
       "9274                        NaN       NaN             NaN  ...   \n",
       "\n",
       "      Gehandicaptentoilet  Kieskring ID  Hoofdstembureau Tellocatie  \\\n",
       "0                      ja  Valkenswaard     Valkenswaard        NaN   \n",
       "1                     NaN  Valkenswaard     Valkenswaard        NaN   \n",
       "2                     NaN  Valkenswaard     Valkenswaard        NaN   \n",
       "3                     NaN  Valkenswaard     Valkenswaard        NaN   \n",
       "4                     NaN  Valkenswaard     Valkenswaard        NaN   \n",
       "...                   ...           ...              ...        ...   \n",
       "9270                  NaN        Gennep           Gennep         ja   \n",
       "9271                  NaN        Gennep           Gennep         ja   \n",
       "9272                  NaN        Gennep           Gennep         ja   \n",
       "9273                  NaN        Gennep           Gennep         ja   \n",
       "9274                  NaN        Gennep           Gennep        NaN   \n",
       "\n",
       "                               Contactgegevens gemeente  \\\n",
       "0                          verkiezingen@valkenswaard.nl   \n",
       "1                          verkiezingen@valkenswaard.nl   \n",
       "2                          verkiezingen@valkenswaard.nl   \n",
       "3                          verkiezingen@valkenswaard.nl   \n",
       "4                          verkiezingen@valkenswaard.nl   \n",
       "...                                                 ...   \n",
       "9270  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9271  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9272  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9273  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9274  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "\n",
       "                  Verkiezingswebsite gemeente Verkiezingen  \\\n",
       "0     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "1     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "2     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "3     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "4     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "...                                       ...          ...   \n",
       "9270                    https://www.gennep.nl          NaN   \n",
       "9271                    https://www.gennep.nl          NaN   \n",
       "9272                    https://www.gennep.nl          NaN   \n",
       "9273                    https://www.gennep.nl          NaN   \n",
       "9274                    https://www.gennep.nl          NaN   \n",
       "\n",
       "                                     ID                              UUID  \\\n",
       "0     NLODSGM0858stembureaus20220316009  3a612b2151fa4ab491b9e331355e6258   \n",
       "1     NLODSGM0858stembureaus20220316009  9a01d765af0a467ea37f08d92db114ba   \n",
       "2     NLODSGM0858stembureaus20220316009  fc5869d33fbc4b06be659149fa615f4c   \n",
       "3     NLODSGM0858stembureaus20220316009  4427cc0b39e040ba8f75c333f19d66f0   \n",
       "4     NLODSGM0858stembureaus20220316009  a893bb9add324ce29769f1c39afcc48d   \n",
       "...                                 ...                               ...   \n",
       "9270  NLODSGM0907stembureaus20220316009  f744546cd6894e5e9a4db4bbfd81b4ee   \n",
       "9271  NLODSGM0907stembureaus20220316009  1270081b1dc74cd7bea0f45973650408   \n",
       "9272  NLODSGM0907stembureaus20220316009  447c7742604345139e41def4cf1e4d3c   \n",
       "9273  NLODSGM0907stembureaus20220316009  049cfd258c174bc49abf17883396d083   \n",
       "9274  NLODSGM0907stembureaus20220316009  1e8cbe96e72c4c6ba6303f47bec8cdb5   \n",
       "\n",
       "                      geometry  \n",
       "0     POINT (5.45515 51.34711)  \n",
       "1     POINT (5.45137 51.34955)  \n",
       "2     POINT (5.44827 51.35702)  \n",
       "3     POINT (5.44871 51.36022)  \n",
       "4     POINT (5.45331 51.36514)  \n",
       "...                        ...  \n",
       "9270  POINT (5.98266 51.69726)  \n",
       "9271  POINT (5.98127 51.69000)  \n",
       "9272  POINT (5.95118 51.72591)  \n",
       "9273  POINT (6.01556 51.70976)  \n",
       "9274  POINT (5.98514 51.70189)  \n",
       "\n",
       "[9275 rows x 41 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Convert the wims data to a geopandas dataframe\n",
    "gdf_wims = gpd.GeoDataFrame(\n",
    "    df_wims,\n",
    "    geometry=gpd.points_from_xy(df_wims.Longitude, df_wims.Latitude)\n",
    ").set_crs(epsg=4326, inplace=True)\n",
    "\n",
    "gdf_wims"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>_id</th>\n",
       "      <th>Gemeente</th>\n",
       "      <th>CBS gemeentecode</th>\n",
       "      <th>Nummer stembureau</th>\n",
       "      <th>Naam stembureau</th>\n",
       "      <th>Gebruiksdoel van het gebouw</th>\n",
       "      <th>Website locatie</th>\n",
       "      <th>Wijknaam</th>\n",
       "      <th>CBS wijknummer</th>\n",
       "      <th>...</th>\n",
       "      <th>Gehandicaptentoilet</th>\n",
       "      <th>Kieskring ID</th>\n",
       "      <th>Hoofdstembureau</th>\n",
       "      <th>Tellocatie</th>\n",
       "      <th>Contactgegevens gemeente</th>\n",
       "      <th>Verkiezingswebsite gemeente</th>\n",
       "      <th>Verkiezingen</th>\n",
       "      <th>ID</th>\n",
       "      <th>UUID</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>1</td>\n",
       "      <td>Zorgcentrum Kempenhof</td>\n",
       "      <td>gezondheidszorgfunctie</td>\n",
       "      <td>https://www.valkenhof.nl/</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>ja</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>3a612b2151fa4ab491b9e331355e6258</td>\n",
       "      <td>POINT (5.45515 51.34711)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>2</td>\n",
       "      <td>Buurtgebouw De Horizon</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>9a01d765af0a467ea37f08d92db114ba</td>\n",
       "      <td>POINT (5.45137 51.34955)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>3</td>\n",
       "      <td>Speeltuin Geenhoven</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>fc5869d33fbc4b06be659149fa615f4c</td>\n",
       "      <td>POINT (5.44827 51.35702)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>4</td>\n",
       "      <td>Ontmoetingscentrum De zoete inval</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>4427cc0b39e040ba8f75c333f19d66f0</td>\n",
       "      <td>POINT (5.44871 51.36022)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>5</td>\n",
       "      <td>Gymnastiekzaal 't Gegraaf</td>\n",
       "      <td>sportfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@valkenswaard.nl</td>\n",
       "      <td>http://www.valkenswaard.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0858stembureaus20220316009</td>\n",
       "      <td>a893bb9add324ce29769f1c39afcc48d</td>\n",
       "      <td>POINT (5.45331 51.36514)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9270</th>\n",
       "      <td>9270</td>\n",
       "      <td>38745</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>4</td>\n",
       "      <td>Het Hökske</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>f744546cd6894e5e9a4db4bbfd81b4ee</td>\n",
       "      <td>POINT (5.98266 51.69726)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9271</th>\n",
       "      <td>9271</td>\n",
       "      <td>38746</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>5</td>\n",
       "      <td>Buurthuis VanOns</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>1270081b1dc74cd7bea0f45973650408</td>\n",
       "      <td>POINT (5.98127 51.69000)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9272</th>\n",
       "      <td>9272</td>\n",
       "      <td>38747</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>6</td>\n",
       "      <td>'t Trefpunt</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>447c7742604345139e41def4cf1e4d3c</td>\n",
       "      <td>POINT (5.95118 51.72591)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9273</th>\n",
       "      <td>9273</td>\n",
       "      <td>38748</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>8</td>\n",
       "      <td>De Uitkomst</td>\n",
       "      <td>bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>ja</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>049cfd258c174bc49abf17883396d083</td>\n",
       "      <td>POINT (6.01556 51.70976)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9274</th>\n",
       "      <td>9274</td>\n",
       "      <td>38749</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>1</td>\n",
       "      <td>Zaal Buurman</td>\n",
       "      <td>woonfunctie,bijeenkomstfunctie</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Klantcontactcentrum gemeente Gennep gemeente@g...</td>\n",
       "      <td>https://www.gennep.nl</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0907stembureaus20220316009</td>\n",
       "      <td>1e8cbe96e72c4c6ba6303f47bec8cdb5</td>\n",
       "      <td>POINT (5.98514 51.70189)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8089 rows × 41 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Unnamed: 0    _id      Gemeente CBS gemeentecode  Nummer stembureau  \\\n",
       "0              0      1  Valkenswaard           GM0858                  1   \n",
       "1              1      2  Valkenswaard           GM0858                  2   \n",
       "2              2      3  Valkenswaard           GM0858                  3   \n",
       "3              3      4  Valkenswaard           GM0858                  4   \n",
       "4              4      5  Valkenswaard           GM0858                  5   \n",
       "...          ...    ...           ...              ...                ...   \n",
       "9270        9270  38745        Gennep           GM0907                  4   \n",
       "9271        9271  38746        Gennep           GM0907                  5   \n",
       "9272        9272  38747        Gennep           GM0907                  6   \n",
       "9273        9273  38748        Gennep           GM0907                  8   \n",
       "9274        9274  38749        Gennep           GM0907                  1   \n",
       "\n",
       "                        Naam stembureau     Gebruiksdoel van het gebouw  \\\n",
       "0                 Zorgcentrum Kempenhof          gezondheidszorgfunctie   \n",
       "1                Buurtgebouw De Horizon              bijeenkomstfunctie   \n",
       "2                   Speeltuin Geenhoven              bijeenkomstfunctie   \n",
       "3     Ontmoetingscentrum De zoete inval              bijeenkomstfunctie   \n",
       "4             Gymnastiekzaal 't Gegraaf                    sportfunctie   \n",
       "...                                 ...                             ...   \n",
       "9270                         Het Hökske              bijeenkomstfunctie   \n",
       "9271                   Buurthuis VanOns              bijeenkomstfunctie   \n",
       "9272                        't Trefpunt              bijeenkomstfunctie   \n",
       "9273                        De Uitkomst              bijeenkomstfunctie   \n",
       "9274                       Zaal Buurman  woonfunctie,bijeenkomstfunctie   \n",
       "\n",
       "                Website locatie  Wijknaam  CBS wijknummer  ...  \\\n",
       "0     https://www.valkenhof.nl/       NaN             NaN  ...   \n",
       "1                           NaN       NaN             NaN  ...   \n",
       "2                           NaN       NaN             NaN  ...   \n",
       "3                           NaN       NaN             NaN  ...   \n",
       "4                           NaN       NaN             NaN  ...   \n",
       "...                         ...       ...             ...  ...   \n",
       "9270                        NaN       NaN             NaN  ...   \n",
       "9271                        NaN       NaN             NaN  ...   \n",
       "9272                        NaN       NaN             NaN  ...   \n",
       "9273                        NaN       NaN             NaN  ...   \n",
       "9274                        NaN       NaN             NaN  ...   \n",
       "\n",
       "      Gehandicaptentoilet  Kieskring ID  Hoofdstembureau Tellocatie  \\\n",
       "0                      ja  Valkenswaard     Valkenswaard        NaN   \n",
       "1                     NaN  Valkenswaard     Valkenswaard        NaN   \n",
       "2                     NaN  Valkenswaard     Valkenswaard        NaN   \n",
       "3                     NaN  Valkenswaard     Valkenswaard        NaN   \n",
       "4                     NaN  Valkenswaard     Valkenswaard        NaN   \n",
       "...                   ...           ...              ...        ...   \n",
       "9270                  NaN        Gennep           Gennep         ja   \n",
       "9271                  NaN        Gennep           Gennep         ja   \n",
       "9272                  NaN        Gennep           Gennep         ja   \n",
       "9273                  NaN        Gennep           Gennep         ja   \n",
       "9274                  NaN        Gennep           Gennep        NaN   \n",
       "\n",
       "                               Contactgegevens gemeente  \\\n",
       "0                          verkiezingen@valkenswaard.nl   \n",
       "1                          verkiezingen@valkenswaard.nl   \n",
       "2                          verkiezingen@valkenswaard.nl   \n",
       "3                          verkiezingen@valkenswaard.nl   \n",
       "4                          verkiezingen@valkenswaard.nl   \n",
       "...                                                 ...   \n",
       "9270  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9271  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9272  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9273  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "9274  Klantcontactcentrum gemeente Gennep gemeente@g...   \n",
       "\n",
       "                  Verkiezingswebsite gemeente Verkiezingen  \\\n",
       "0     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "1     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "2     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "3     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "4     http://www.valkenswaard.nl/verkiezingen          NaN   \n",
       "...                                       ...          ...   \n",
       "9270                    https://www.gennep.nl          NaN   \n",
       "9271                    https://www.gennep.nl          NaN   \n",
       "9272                    https://www.gennep.nl          NaN   \n",
       "9273                    https://www.gennep.nl          NaN   \n",
       "9274                    https://www.gennep.nl          NaN   \n",
       "\n",
       "                                     ID                              UUID  \\\n",
       "0     NLODSGM0858stembureaus20220316009  3a612b2151fa4ab491b9e331355e6258   \n",
       "1     NLODSGM0858stembureaus20220316009  9a01d765af0a467ea37f08d92db114ba   \n",
       "2     NLODSGM0858stembureaus20220316009  fc5869d33fbc4b06be659149fa615f4c   \n",
       "3     NLODSGM0858stembureaus20220316009  4427cc0b39e040ba8f75c333f19d66f0   \n",
       "4     NLODSGM0858stembureaus20220316009  a893bb9add324ce29769f1c39afcc48d   \n",
       "...                                 ...                               ...   \n",
       "9270  NLODSGM0907stembureaus20220316009  f744546cd6894e5e9a4db4bbfd81b4ee   \n",
       "9271  NLODSGM0907stembureaus20220316009  1270081b1dc74cd7bea0f45973650408   \n",
       "9272  NLODSGM0907stembureaus20220316009  447c7742604345139e41def4cf1e4d3c   \n",
       "9273  NLODSGM0907stembureaus20220316009  049cfd258c174bc49abf17883396d083   \n",
       "9274  NLODSGM0907stembureaus20220316009  1e8cbe96e72c4c6ba6303f47bec8cdb5   \n",
       "\n",
       "                      geometry  \n",
       "0     POINT (5.45515 51.34711)  \n",
       "1     POINT (5.45137 51.34955)  \n",
       "2     POINT (5.44827 51.35702)  \n",
       "3     POINT (5.44871 51.36022)  \n",
       "4     POINT (5.45331 51.36514)  \n",
       "...                        ...  \n",
       "9270  POINT (5.98266 51.69726)  \n",
       "9271  POINT (5.98127 51.69000)  \n",
       "9272  POINT (5.95118 51.72591)  \n",
       "9273  POINT (6.01556 51.70976)  \n",
       "9274  POINT (5.98514 51.70189)  \n",
       "\n",
       "[8089 rows x 41 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# We only want to analyse stemlokalen so deduplicate the stembureaus based on their location's coordinates\n",
    "gdf_wims_dedupe = gdf_wims.drop_duplicates(subset=\"geometry\", keep=False)\n",
    "df_geojson_dedupe = df_geojson_clean.drop_duplicates(subset=\"geometry\", keep=False)\n",
    "gdf_wims_dedupe"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Voor dit onderzoek zijn we enkel geïnteresseerd in de locaties van stembureaus, oftewel de stemlokalen. Hierboven hebben we de stembureaus uit de wims dataset gededupliceerd op basis van de coördinaten van hun locatie.\n",
    "\n",
    "Het aantal stembureaus: 9275\n",
    "\n",
    "Het aantal stemlokalen: 8089\n",
    "\n",
    "Er zijn dus 1186 stembureaus gevestigd op een locatie van minimaal één ander stembureau."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plots van alle stemlokalen op de kaart\n",
    "### Stemlokalen uit de wims dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 212568 characters]",
      "text/plain": [
       "<Figure size 1080x1080 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots(figsize = (15,15))\n",
    "nl_map.to_crs(epsg=4326).plot(ax=ax, color='lightgrey')\n",
    "gdf_wims_dedupe.plot(ax=ax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Stemlokalen uit de OSF/VK GeoJSON dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 211792 characters]",
      "text/plain": [
       "<Figure size 1080x1080 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots(figsize = (15,15))\n",
    "nl_map.to_crs(epsg=4326).plot(ax=ax, color='lightgrey')\n",
    "df_geojson_clean.plot(ax=ax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Nu we een kaart van nederland met de stemlokalen erop hebben, kunnen we als eerste voorbeeld gaan kijken hoe dit zich verhoudt met de bevolkingsdichtheid. De kaart is opgehaald van het CBS, eerst gaan we kijken hoe de kaart er op zichzelf met dezelfde projectie uitziet."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 43592 characters]",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "nl_map_cbs = gpd.read_file(r'../data/shape/Netherlands_shapefile/cbs_vk500_2021_v1.gpkg')\n",
    "nl_map_cbs.to_crs(epsg=4326).plot()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Het verwerken van de 100m bij 100m vierkanten kaart duurde 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 (wat lang duurt), 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."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11165         0.002608\n",
      "1021          0.004853\n",
      "3196          0.004875\n",
      "1923          2.693202\n",
      "3757          3.609362\n",
      "             ...      \n",
      "7444     253385.654588\n",
      "9711     263408.187856\n",
      "4392     266925.200994\n",
      "9297     271954.076837\n",
      "0                  NaN\n",
      "Name: distance, Length: 11670, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# Use Rijksdriehoekscoördinaten (EPSG:28992) as this uses meters as unit so we can calculate the distance in meters\n",
    "df_shifted = df_geojson_clean.to_crs('EPSG:28992')\n",
    "\n",
    "df_shifted['geometry (shifted)'] = df_shifted['geometry'].shift(periods=1)\n",
    "df_shifted['distance'] = df_shifted['geometry'].distance(df_shifted['geometry (shifted)'])\n",
    "df_shifted.sort_values(['distance'], inplace=True, ascending=True)\n",
    "zero_mask_booth = df_shifted['distance'] == 0.000000\n",
    "df_shifted = df_shifted[~zero_mask_booth]\n",
    "print(df_shifted['distance'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Los van bovenstaande resultaten blijkt het dat de 100m kaart niet dezelfde inwonersgegevens heeft als de 500m kaart. Deze hebben we echter nodig voor de analyse, dus we gaan verder met de 500 bij 500 meter kaart. Laten we nu een projectie proberen te maken met de bevolkingsdichtheid erop om het te vergelijken met de stemlokalen en hun posities en clustering."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['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']\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>crs28992res500m</th>\n",
       "      <th>aantal_inwoners</th>\n",
       "      <th>stedelijkheid</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>E2260N6190</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>MULTIPOLYGON (((226000.000 619000.000, 226000....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>E2265N6190</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>MULTIPOLYGON (((226500.000 619500.000, 227000....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>E2270N6190</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>MULTIPOLYGON (((227000.000 619500.000, 227500....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>E2275N6190</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>MULTIPOLYGON (((227500.000 619500.000, 228000....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>E2280N6190</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>MULTIPOLYGON (((228000.000 619500.000, 228500....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151103</th>\n",
       "      <td>E1995N3070</td>\n",
       "      <td>-99997</td>\n",
       "      <td>5</td>\n",
       "      <td>MULTIPOLYGON (((199500.000 307500.000, 200000....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151104</th>\n",
       "      <td>E1905N3065</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>MULTIPOLYGON (((190500.000 307000.000, 191000....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151105</th>\n",
       "      <td>E1910N3065</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>MULTIPOLYGON (((191000.000 307000.000, 191500....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151106</th>\n",
       "      <td>E1920N3065</td>\n",
       "      <td>15</td>\n",
       "      <td>5</td>\n",
       "      <td>MULTIPOLYGON (((192000.000 307000.000, 192500....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151107</th>\n",
       "      <td>E1925N3065</td>\n",
       "      <td>-99997</td>\n",
       "      <td>5</td>\n",
       "      <td>MULTIPOLYGON (((192500.000 307000.000, 193000....</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>151108 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       crs28992res500m  aantal_inwoners  stedelijkheid  \\\n",
       "0           E2260N6190           -99997         -99997   \n",
       "1           E2265N6190           -99997         -99997   \n",
       "2           E2270N6190           -99997         -99997   \n",
       "3           E2275N6190           -99997         -99997   \n",
       "4           E2280N6190           -99997         -99997   \n",
       "...                ...              ...            ...   \n",
       "151103      E1995N3070           -99997              5   \n",
       "151104      E1905N3065           -99997         -99997   \n",
       "151105      E1910N3065           -99997         -99997   \n",
       "151106      E1920N3065               15              5   \n",
       "151107      E1925N3065           -99997              5   \n",
       "\n",
       "                                                 geometry  \n",
       "0       MULTIPOLYGON (((226000.000 619000.000, 226000....  \n",
       "1       MULTIPOLYGON (((226500.000 619500.000, 227000....  \n",
       "2       MULTIPOLYGON (((227000.000 619500.000, 227500....  \n",
       "3       MULTIPOLYGON (((227500.000 619500.000, 228000....  \n",
       "4       MULTIPOLYGON (((228000.000 619500.000, 228500....  \n",
       "...                                                   ...  \n",
       "151103  MULTIPOLYGON (((199500.000 307500.000, 200000....  \n",
       "151104  MULTIPOLYGON (((190500.000 307000.000, 191000....  \n",
       "151105  MULTIPOLYGON (((191000.000 307000.000, 191500....  \n",
       "151106  MULTIPOLYGON (((192000.000 307000.000, 192500....  \n",
       "151107  MULTIPOLYGON (((192500.000 307000.000, 193000....  \n",
       "\n",
       "[151108 rows x 4 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(list(nl_map_cbs))\n",
    "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'])\n",
    "\n",
    "nl_map_dst"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We kunnen zien dat er gemeente zijn die geen stemlokalen hebben, dit klopt. [In de verkiezingen van 2022 hebben 12 gemeentes niet meegedaan](https://nl.wikipedia.org/wiki/Nederlandse_gemeenteraadsverkiezingen_2022). 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."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0             Gemeenteraad Aa en Hunze 2022\n",
      "1             Gemeenteraad Aa en Hunze 2022\n",
      "2             Gemeenteraad Aa en Hunze 2022\n",
      "3             Gemeenteraad Aa en Hunze 2022\n",
      "4             Gemeenteraad Aa en Hunze 2022\n",
      "                        ...                \n",
      "12591    Gemeenteraad 's-Hertogenbosch 2022\n",
      "12592    Gemeenteraad 's-Hertogenbosch 2022\n",
      "12593    Gemeenteraad 's-Hertogenbosch 2022\n",
      "12594    Gemeenteraad 's-Hertogenbosch 2022\n",
      "12595    Gemeenteraad 's-Hertogenbosch 2022\n",
      "Name: electionName, Length: 12596, dtype: object\n",
      "0             Aa en Hunze\n",
      "27               Aalsmeer\n",
      "46                 Aalten\n",
      "74          Achtkarspelen\n",
      "95           Alblasserdam\n",
      "               ...       \n",
      "11976     Zwartewaterland\n",
      "11997         Zwijndrecht\n",
      "12031              Zwolle\n",
      "12122       's-Gravenhage\n",
      "12495    's-Hertogenbosch\n",
      "Name: electionName, Length: 333, dtype: object\n"
     ]
    }
   ],
   "source": [
    "print(df_geojson['electionName'])\n",
    "\n",
    "#get all municipalities that are in the election\n",
    "gemeentes = df_geojson['electionName'].str.slice(13, -5).drop_duplicates()\n",
    "print(gemeentes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Shape of clean: (333, 38)\n",
      "Shape of election: (330, 38)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GM_CODE</th>\n",
       "      <th>GM_NAAM</th>\n",
       "      <th>H2O</th>\n",
       "      <th>OAD</th>\n",
       "      <th>STED</th>\n",
       "      <th>BEV_DICHTH</th>\n",
       "      <th>AANT_INW</th>\n",
       "      <th>AANT_MAN</th>\n",
       "      <th>AANT_VROUW</th>\n",
       "      <th>P_00_14_JR</th>\n",
       "      <th>...</th>\n",
       "      <th>P_TURKIJE</th>\n",
       "      <th>P_OVER_NW</th>\n",
       "      <th>OPP_TOT</th>\n",
       "      <th>OPP_LAND</th>\n",
       "      <th>OPP_WATER</th>\n",
       "      <th>JRSTATCODE</th>\n",
       "      <th>JAAR</th>\n",
       "      <th>Shape_Leng</th>\n",
       "      <th>Shape_Area</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>GM0164</td>\n",
       "      <td>Hengelo</td>\n",
       "      <td>NEE</td>\n",
       "      <td>1845</td>\n",
       "      <td>2</td>\n",
       "      <td>1332</td>\n",
       "      <td>81049</td>\n",
       "      <td>40776</td>\n",
       "      <td>40273</td>\n",
       "      <td>15</td>\n",
       "      <td>...</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>6183</td>\n",
       "      <td>6084</td>\n",
       "      <td>99</td>\n",
       "      <td>2021GM0164</td>\n",
       "      <td>2021</td>\n",
       "      <td>47510.255914</td>\n",
       "      <td>6.183056e+07</td>\n",
       "      <td>POLYGON ((251978.591 481220.258, 251979.382 48...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>191</th>\n",
       "      <td>GM0373</td>\n",
       "      <td>Bergen (NH.)</td>\n",
       "      <td>NEE</td>\n",
       "      <td>819</td>\n",
       "      <td>4</td>\n",
       "      <td>300</td>\n",
       "      <td>29715</td>\n",
       "      <td>14317</td>\n",
       "      <td>15398</td>\n",
       "      <td>12</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>12023</td>\n",
       "      <td>9896</td>\n",
       "      <td>2127</td>\n",
       "      <td>2021GM0373</td>\n",
       "      <td>2021</td>\n",
       "      <td>57488.474563</td>\n",
       "      <td>9.987418e+07</td>\n",
       "      <td>POLYGON ((105976.650 529056.951, 106002.347 52...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>328</th>\n",
       "      <td>GM0893</td>\n",
       "      <td>Bergen (L.)</td>\n",
       "      <td>NEE</td>\n",
       "      <td>318</td>\n",
       "      <td>5</td>\n",
       "      <td>127</td>\n",
       "      <td>13108</td>\n",
       "      <td>6568</td>\n",
       "      <td>6540</td>\n",
       "      <td>13</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>10850</td>\n",
       "      <td>10324</td>\n",
       "      <td>525</td>\n",
       "      <td>2021GM0893</td>\n",
       "      <td>2021</td>\n",
       "      <td>61497.563571</td>\n",
       "      <td>1.084951e+08</td>\n",
       "      <td>POLYGON ((199768.270 409749.960, 199758.060 40...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 38 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    GM_CODE       GM_NAAM  H2O   OAD  STED  BEV_DICHTH  AANT_INW  AANT_MAN  \\\n",
       "113  GM0164       Hengelo  NEE  1845     2        1332     81049     40776   \n",
       "191  GM0373  Bergen (NH.)  NEE   819     4         300     29715     14317   \n",
       "328  GM0893   Bergen (L.)  NEE   318     5         127     13108      6568   \n",
       "\n",
       "     AANT_VROUW  P_00_14_JR  ...  P_TURKIJE  P_OVER_NW  OPP_TOT  OPP_LAND  \\\n",
       "113       40273          15  ...          6          7     6183      6084   \n",
       "191       15398          12  ...          0          3    12023      9896   \n",
       "328        6540          13  ...          0          3    10850     10324   \n",
       "\n",
       "     OPP_WATER  JRSTATCODE  JAAR    Shape_Leng    Shape_Area  \\\n",
       "113         99  2021GM0164  2021  47510.255914  6.183056e+07   \n",
       "191       2127  2021GM0373  2021  57488.474563  9.987418e+07   \n",
       "328        525  2021GM0893  2021  61497.563571  1.084951e+08   \n",
       "\n",
       "                                              geometry  \n",
       "113  POLYGON ((251978.591 481220.258, 251979.382 48...  \n",
       "191  POLYGON ((105976.650 529056.951, 106002.347 52...  \n",
       "328  POLYGON ((199768.270 409749.960, 199758.060 40...  \n",
       "\n",
       "[3 rows x 38 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#First let's remove the municipalities that don't have an Election from the municipality map\n",
    "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\"]\n",
    "\n",
    "\n",
    "nl_map_clean = nl_map[~nl_map[\"GM_NAAM\"].isin(remove_lst)]\n",
    "nl_map_clean = nl_map_clean.query(\"H2O != 'JA'\")\n",
    "nl_map_clean = nl_map_clean.query(\"GM_NAAM != 'Buitenland'\")\n",
    "\n",
    "\n",
    "nl_map_election = nl_map[nl_map[\"GM_NAAM\"].isin(gemeentes)]\n",
    "nl_map_election = nl_map_election.query(\"H2O != 'JA'\")\n",
    "\n",
    "print(\"Shape of clean: {}\".format(nl_map_clean.shape))\n",
    "print(\"Shape of election: {}\".format(nl_map_election.shape))\n",
    "\n",
    "diff = pd.concat([nl_map_election, nl_map_clean]).drop_duplicates(keep=False)\n",
    "diff"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "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.\n",
    "Nu we dezelfde lijst hebben van gemeentes die in de verkiezingen meededen kunnen we verder."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 216112 characters]",
      "text/plain": [
       "<Figure size 1080x1080 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots(figsize = (15,15))\n",
    "nl_map_clean.to_crs(epsg=4326).plot(ax=ax, color='lightgrey')\n",
    "df_geojson_clean.plot(ax=ax)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 45180 characters]",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "nl_map_dst['savedindex'] = nl_map_dst.index #Save the index values as a new column\n",
    "\n",
    "intersecting = nl_map_clean.sjoin(nl_map_dst, how='inner')['savedindex'] #Find the polygons that intersect. Keep savedindex as a series\n",
    "\n",
    "nl_map_dst = nl_map_dst.loc[nl_map_dst.savedindex.isin(intersecting)] #Filter away these, \"savedindex is in intersecting\"\n",
    "\n",
    "nl_map_dst.to_crs(epsg=4326).plot()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "import folium\n",
    "from folium import plugins\n",
    "\n",
    "#Location is Amersfoort, the central point of the continental Netherlands\n",
    "map = folium.Map(location = [52.155, 5.3875], zoom_start = 9, tiles=\"cartodbdark_matter\", prefer_canvas=True)\n",
    "\n",
    "nl_map_dst.to_crs(epsg=4326)\n",
    "#Make sure the index is a string so folium can read it correctly as a key.\n",
    "nl_map_dst['crs28992res500m'] = nl_map_dst['crs28992res500m'].apply(lambda x: str(x))\n",
    "\n",
    "nl_map_dst_zero = nl_map_dst.copy()\n",
    "\n",
    "zero_mask_pop = nl_map_dst['aantal_inwoners'] == -99997\n",
    "nl_map_dst = nl_map_dst[~zero_mask_pop]\n",
    "zero_mask_pop2 = nl_map_dst['aantal_inwoners'] == 0\n",
    "nl_map_dst = nl_map_dst[~zero_mask_pop2]\n",
    "\n",
    "folium.Choropleth(\n",
    "    geo_data = nl_map_dst,\n",
    "    name=\"Bevolkingsdichtheid\",\n",
    "    data = nl_map_dst,\n",
    "    columns = [\"crs28992res500m\", \"aantal_inwoners\"],\n",
    "    key_on = 'feature.properties.crs28992res500m',\n",
    "    fill_color = 'RdPu',\n",
    "    nan_fill_color= 'white',\n",
    "    fill_opacity = 0.7,\n",
    "    nan_fill_opacity = 0.7,\n",
    "    line_opacity = 0,\n",
    "    legend_name = 'Bevolkingsdichtheid',\n",
    "    smooth_factor = 1.0,\n",
    "    show=False\n",
    ").add_to(map)\n",
    "map\n",
    "\n",
    "# Renders the map to an HTML file and displays it in an embed.\n",
    "def embed_map(m):\n",
    "    #from IPython.display import IFrame\n",
    "    m.save('index.html')\n",
    "    #return IFrame('index.html', width='100%', height='750px')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "gdf_wims_hmp = [[point.xy[1][0], point.xy[0][0]] for point in gdf_wims.geometry]\n",
    "\n",
    "plugins.HeatMap(gdf_wims_hmp, name=\"Stemlokalen Heatmap\").add_to(map)\n",
    "\n",
    "folium.LayerControl().add_to(map)\n",
    "\n",
    "\n",
    "\n",
    "embed_map(map)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>crs28992res500m</th>\n",
       "      <th>aantal_inwoners</th>\n",
       "      <th>stedelijkheid</th>\n",
       "      <th>geometry</th>\n",
       "      <th>savedindex</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>E2270N6190</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (227250.000 619250.000)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>E2275N6190</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (227750.000 619250.000)</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>E2280N6190</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (228250.000 619250.000)</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>E2265N6185</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (226750.000 618750.000)</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>E2270N6185</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (227250.000 618750.000)</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151102</th>\n",
       "      <td>E1990N3070</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (199250.000 307250.000)</td>\n",
       "      <td>151102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151103</th>\n",
       "      <td>E1995N3070</td>\n",
       "      <td>-99997</td>\n",
       "      <td>5</td>\n",
       "      <td>POINT (199750.000 307250.000)</td>\n",
       "      <td>151103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151105</th>\n",
       "      <td>E1910N3065</td>\n",
       "      <td>-99997</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (191250.000 306750.000)</td>\n",
       "      <td>151105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151106</th>\n",
       "      <td>E1920N3065</td>\n",
       "      <td>15</td>\n",
       "      <td>5</td>\n",
       "      <td>POINT (192250.000 306750.000)</td>\n",
       "      <td>151106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151107</th>\n",
       "      <td>E1925N3065</td>\n",
       "      <td>-99997</td>\n",
       "      <td>5</td>\n",
       "      <td>POINT (192750.000 306750.000)</td>\n",
       "      <td>151107</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>140002 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       crs28992res500m  aantal_inwoners  stedelijkheid  \\\n",
       "2           E2270N6190           -99997         -99997   \n",
       "3           E2275N6190           -99997         -99997   \n",
       "4           E2280N6190           -99997         -99997   \n",
       "7           E2265N6185           -99997         -99997   \n",
       "8           E2270N6185           -99997         -99997   \n",
       "...                ...              ...            ...   \n",
       "151102      E1990N3070           -99997         -99997   \n",
       "151103      E1995N3070           -99997              5   \n",
       "151105      E1910N3065           -99997         -99997   \n",
       "151106      E1920N3065               15              5   \n",
       "151107      E1925N3065           -99997              5   \n",
       "\n",
       "                             geometry  savedindex  \n",
       "2       POINT (227250.000 619250.000)           2  \n",
       "3       POINT (227750.000 619250.000)           3  \n",
       "4       POINT (228250.000 619250.000)           4  \n",
       "7       POINT (226750.000 618750.000)           7  \n",
       "8       POINT (227250.000 618750.000)           8  \n",
       "...                               ...         ...  \n",
       "151102  POINT (199250.000 307250.000)      151102  \n",
       "151103  POINT (199750.000 307250.000)      151103  \n",
       "151105  POINT (191250.000 306750.000)      151105  \n",
       "151106  POINT (192250.000 306750.000)      151106  \n",
       "151107  POINT (192750.000 306750.000)      151107  \n",
       "\n",
       "[140002 rows x 5 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nl_map_dst_points = nl_map_dst.copy()\n",
    "nl_map_dst_points['geometry'] = nl_map_dst_points['geometry'].centroid\n",
    "\n",
    "nl_map_dst_zero_points = nl_map_dst_zero.copy()\n",
    "nl_map_dst_zero_points['geometry'] = nl_map_dst_zero_points['geometry'].centroid\n",
    "\n",
    "nl_map_dst_zero_points"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>crs28992res500m</th>\n",
       "      <th>aantal_inwoners</th>\n",
       "      <th>stedelijkheid</th>\n",
       "      <th>geometry</th>\n",
       "      <th>savedindex</th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>_id</th>\n",
       "      <th>Gemeente</th>\n",
       "      <th>CBS gemeentecode</th>\n",
       "      <th>Nummer stembureau</th>\n",
       "      <th>...</th>\n",
       "      <th>Gehandicaptentoilet</th>\n",
       "      <th>Kieskring ID</th>\n",
       "      <th>Hoofdstembureau</th>\n",
       "      <th>Tellocatie</th>\n",
       "      <th>Contactgegevens gemeente</th>\n",
       "      <th>Verkiezingswebsite gemeente</th>\n",
       "      <th>Verkiezingen</th>\n",
       "      <th>ID</th>\n",
       "      <th>UUID</th>\n",
       "      <th>dist</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>E2050N6110</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>POINT (205250.000 611250.000)</td>\n",
       "      <td>267</td>\n",
       "      <td>5710</td>\n",
       "      <td>30871</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>GM0088</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>ja</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>NaN</td>\n",
       "      <td>postbus20@schiermonnikoog.nl, 0519-535050</td>\n",
       "      <td>https://www.schiermonnikoog.nl/in-de-gemeente/...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0088stembureaus20220316009</td>\n",
       "      <td>35abba36eca7485c89e82b2917633ae7</td>\n",
       "      <td>1331.950309</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>E2060N6110</td>\n",
       "      <td>10</td>\n",
       "      <td>5</td>\n",
       "      <td>POINT (206250.000 611250.000)</td>\n",
       "      <td>269</td>\n",
       "      <td>5710</td>\n",
       "      <td>30871</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>GM0088</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>ja</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>NaN</td>\n",
       "      <td>postbus20@schiermonnikoog.nl, 0519-535050</td>\n",
       "      <td>https://www.schiermonnikoog.nl/in-de-gemeente/...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0088stembureaus20220316009</td>\n",
       "      <td>35abba36eca7485c89e82b2917633ae7</td>\n",
       "      <td>688.536284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>E2055N6105</td>\n",
       "      <td>20</td>\n",
       "      <td>5</td>\n",
       "      <td>POINT (205750.000 610750.000)</td>\n",
       "      <td>292</td>\n",
       "      <td>5710</td>\n",
       "      <td>30871</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>GM0088</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>ja</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>NaN</td>\n",
       "      <td>postbus20@schiermonnikoog.nl, 0519-535050</td>\n",
       "      <td>https://www.schiermonnikoog.nl/in-de-gemeente/...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0088stembureaus20220316009</td>\n",
       "      <td>35abba36eca7485c89e82b2917633ae7</td>\n",
       "      <td>672.375861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>E2060N6105</td>\n",
       "      <td>185</td>\n",
       "      <td>5</td>\n",
       "      <td>POINT (206250.000 610750.000)</td>\n",
       "      <td>293</td>\n",
       "      <td>5710</td>\n",
       "      <td>30871</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>GM0088</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>ja</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>NaN</td>\n",
       "      <td>postbus20@schiermonnikoog.nl, 0519-535050</td>\n",
       "      <td>https://www.schiermonnikoog.nl/in-de-gemeente/...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0088stembureaus20220316009</td>\n",
       "      <td>35abba36eca7485c89e82b2917633ae7</td>\n",
       "      <td>228.220493</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>E2065N6105</td>\n",
       "      <td>335</td>\n",
       "      <td>5</td>\n",
       "      <td>POINT (206750.000 610750.000)</td>\n",
       "      <td>294</td>\n",
       "      <td>5710</td>\n",
       "      <td>30871</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>GM0088</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>ja</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>Schiermonnikoog</td>\n",
       "      <td>NaN</td>\n",
       "      <td>postbus20@schiermonnikoog.nl, 0519-535050</td>\n",
       "      <td>https://www.schiermonnikoog.nl/in-de-gemeente/...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0088stembureaus20220316009</td>\n",
       "      <td>35abba36eca7485c89e82b2917633ae7</td>\n",
       "      <td>389.974214</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 46 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  crs28992res500m  aantal_inwoners  stedelijkheid  \\\n",
       "0      E2050N6110                5              5   \n",
       "1      E2060N6110               10              5   \n",
       "2      E2055N6105               20              5   \n",
       "3      E2060N6105              185              5   \n",
       "4      E2065N6105              335              5   \n",
       "\n",
       "                        geometry  savedindex  Unnamed: 0    _id  \\\n",
       "0  POINT (205250.000 611250.000)         267        5710  30871   \n",
       "1  POINT (206250.000 611250.000)         269        5710  30871   \n",
       "2  POINT (205750.000 610750.000)         292        5710  30871   \n",
       "3  POINT (206250.000 610750.000)         293        5710  30871   \n",
       "4  POINT (206750.000 610750.000)         294        5710  30871   \n",
       "\n",
       "          Gemeente CBS gemeentecode  Nummer stembureau  ...  \\\n",
       "0  Schiermonnikoog           GM0088                  1  ...   \n",
       "1  Schiermonnikoog           GM0088                  1  ...   \n",
       "2  Schiermonnikoog           GM0088                  1  ...   \n",
       "3  Schiermonnikoog           GM0088                  1  ...   \n",
       "4  Schiermonnikoog           GM0088                  1  ...   \n",
       "\n",
       "  Gehandicaptentoilet     Kieskring ID  Hoofdstembureau  Tellocatie  \\\n",
       "0                  ja  Schiermonnikoog  Schiermonnikoog         NaN   \n",
       "1                  ja  Schiermonnikoog  Schiermonnikoog         NaN   \n",
       "2                  ja  Schiermonnikoog  Schiermonnikoog         NaN   \n",
       "3                  ja  Schiermonnikoog  Schiermonnikoog         NaN   \n",
       "4                  ja  Schiermonnikoog  Schiermonnikoog         NaN   \n",
       "\n",
       "                    Contactgegevens gemeente  \\\n",
       "0  postbus20@schiermonnikoog.nl, 0519-535050   \n",
       "1  postbus20@schiermonnikoog.nl, 0519-535050   \n",
       "2  postbus20@schiermonnikoog.nl, 0519-535050   \n",
       "3  postbus20@schiermonnikoog.nl, 0519-535050   \n",
       "4  postbus20@schiermonnikoog.nl, 0519-535050   \n",
       "\n",
       "                         Verkiezingswebsite gemeente  Verkiezingen  \\\n",
       "0  https://www.schiermonnikoog.nl/in-de-gemeente/...           NaN   \n",
       "1  https://www.schiermonnikoog.nl/in-de-gemeente/...           NaN   \n",
       "2  https://www.schiermonnikoog.nl/in-de-gemeente/...           NaN   \n",
       "3  https://www.schiermonnikoog.nl/in-de-gemeente/...           NaN   \n",
       "4  https://www.schiermonnikoog.nl/in-de-gemeente/...           NaN   \n",
       "\n",
       "                                  ID                              UUID  \\\n",
       "0  NLODSGM0088stembureaus20220316009  35abba36eca7485c89e82b2917633ae7   \n",
       "1  NLODSGM0088stembureaus20220316009  35abba36eca7485c89e82b2917633ae7   \n",
       "2  NLODSGM0088stembureaus20220316009  35abba36eca7485c89e82b2917633ae7   \n",
       "3  NLODSGM0088stembureaus20220316009  35abba36eca7485c89e82b2917633ae7   \n",
       "4  NLODSGM0088stembureaus20220316009  35abba36eca7485c89e82b2917633ae7   \n",
       "\n",
       "          dist  \n",
       "0  1331.950309  \n",
       "1   688.536284  \n",
       "2   672.375861  \n",
       "3   228.220493  \n",
       "4   389.974214  \n",
       "\n",
       "[5 rows x 46 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "from scipy.spatial import cKDTree\n",
    "from shapely.geometry import Point\n",
    "#Found on https://gis.stackexchange.com/questions/222315/finding-nearest-point-in-other-geodataframe-using-geopandas\n",
    "def ckdnearest(gdA, gdB):\n",
    "\n",
    "    nA = np.array(list(gdA.geometry.apply(lambda x: (x.x, x.y))))\n",
    "    nB = np.array(list(gdB.geometry.apply(lambda x: (x.x, x.y))))\n",
    "    btree = cKDTree(nB)\n",
    "    dist, idx = btree.query(nA, k=1)\n",
    "    gdB_nearest = gdB.iloc[idx].drop(columns=\"geometry\").reset_index(drop=True)\n",
    "    gdf = pd.concat(\n",
    "        [\n",
    "            gdA.reset_index(drop=True),\n",
    "            gdB_nearest,\n",
    "            pd.Series(dist, name='dist')\n",
    "        ], \n",
    "        axis=1)\n",
    "\n",
    "    return gdf\n",
    "\n",
    "#error bar is +- sqrt(250²*2)m ≈ +-353.553390593m\n",
    "error = np.sqrt(250**2 + 250**2)\n",
    "df_nearest = ckdnearest(nl_map_dst_points.to_crs(epsg=28992), gdf_wims_dedupe.to_crs(epsg=28992))\n",
    "df_nearest.head()\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "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."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>crs28992res500m</th>\n",
       "      <th>aantal_inwoners</th>\n",
       "      <th>stedelijkheid</th>\n",
       "      <th>geometry</th>\n",
       "      <th>savedindex</th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>_id</th>\n",
       "      <th>Gemeente</th>\n",
       "      <th>CBS gemeentecode</th>\n",
       "      <th>Nummer stembureau</th>\n",
       "      <th>...</th>\n",
       "      <th>Gehandicaptentoilet</th>\n",
       "      <th>Kieskring ID</th>\n",
       "      <th>Hoofdstembureau</th>\n",
       "      <th>Tellocatie</th>\n",
       "      <th>Contactgegevens gemeente</th>\n",
       "      <th>Verkiezingswebsite gemeente</th>\n",
       "      <th>Verkiezingen</th>\n",
       "      <th>ID</th>\n",
       "      <th>UUID</th>\n",
       "      <th>dist</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>E2270N6190</td>\n",
       "      <td>0</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (227250.000 619250.000)</td>\n",
       "      <td>2</td>\n",
       "      <td>5817</td>\n",
       "      <td>31030</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>GM1966</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@hethogeland.nl</td>\n",
       "      <td>https://hethogeland.nl/bestuur-en-organisatie/...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM1966stembureaus20220316009</td>\n",
       "      <td>6df04b8dd4be4aa3b4a03f221ab5ad17</td>\n",
       "      <td>17236.920436</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>E2275N6190</td>\n",
       "      <td>0</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (227750.000 619250.000)</td>\n",
       "      <td>3</td>\n",
       "      <td>5817</td>\n",
       "      <td>31030</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>GM1966</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@hethogeland.nl</td>\n",
       "      <td>https://hethogeland.nl/bestuur-en-organisatie/...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM1966stembureaus20220316009</td>\n",
       "      <td>6df04b8dd4be4aa3b4a03f221ab5ad17</td>\n",
       "      <td>17280.014918</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>E2280N6190</td>\n",
       "      <td>0</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (228250.000 619250.000)</td>\n",
       "      <td>4</td>\n",
       "      <td>5817</td>\n",
       "      <td>31030</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>GM1966</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@hethogeland.nl</td>\n",
       "      <td>https://hethogeland.nl/bestuur-en-organisatie/...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM1966stembureaus20220316009</td>\n",
       "      <td>6df04b8dd4be4aa3b4a03f221ab5ad17</td>\n",
       "      <td>17337.427867</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>E2265N6185</td>\n",
       "      <td>0</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (226750.000 618750.000)</td>\n",
       "      <td>7</td>\n",
       "      <td>5817</td>\n",
       "      <td>31030</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>GM1966</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@hethogeland.nl</td>\n",
       "      <td>https://hethogeland.nl/bestuur-en-organisatie/...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM1966stembureaus20220316009</td>\n",
       "      <td>6df04b8dd4be4aa3b4a03f221ab5ad17</td>\n",
       "      <td>16708.725120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>E2270N6185</td>\n",
       "      <td>0</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (227250.000 618750.000)</td>\n",
       "      <td>8</td>\n",
       "      <td>5817</td>\n",
       "      <td>31030</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>GM1966</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>Het Hogeland</td>\n",
       "      <td>NaN</td>\n",
       "      <td>verkiezingen@hethogeland.nl</td>\n",
       "      <td>https://hethogeland.nl/bestuur-en-organisatie/...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM1966stembureaus20220316009</td>\n",
       "      <td>6df04b8dd4be4aa3b4a03f221ab5ad17</td>\n",
       "      <td>16738.249149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139997</th>\n",
       "      <td>E1990N3070</td>\n",
       "      <td>0</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (199250.000 307250.000)</td>\n",
       "      <td>151102</td>\n",
       "      <td>498</td>\n",
       "      <td>4103</td>\n",
       "      <td>Vaals</td>\n",
       "      <td>GM0981</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Vaals</td>\n",
       "      <td>Vaals</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Team verkiezingen, verkiezingen2022@vaals.nl</td>\n",
       "      <td>http://www.vaals.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0981stembureaus20220316009</td>\n",
       "      <td>3dfcfccd163145698a33b19623c5c3f3</td>\n",
       "      <td>2010.126740</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139998</th>\n",
       "      <td>E1995N3070</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>POINT (199750.000 307250.000)</td>\n",
       "      <td>151103</td>\n",
       "      <td>498</td>\n",
       "      <td>4103</td>\n",
       "      <td>Vaals</td>\n",
       "      <td>GM0981</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Vaals</td>\n",
       "      <td>Vaals</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Team verkiezingen, verkiezingen2022@vaals.nl</td>\n",
       "      <td>http://www.vaals.nl/verkiezingen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM0981stembureaus20220316009</td>\n",
       "      <td>3dfcfccd163145698a33b19623c5c3f3</td>\n",
       "      <td>1949.951758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139999</th>\n",
       "      <td>E1910N3065</td>\n",
       "      <td>0</td>\n",
       "      <td>-99997</td>\n",
       "      <td>POINT (191250.000 306750.000)</td>\n",
       "      <td>151105</td>\n",
       "      <td>5276</td>\n",
       "      <td>29739</td>\n",
       "      <td>Gulpen-Wittem</td>\n",
       "      <td>GM1729</td>\n",
       "      <td>7</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gulpen-Wittem</td>\n",
       "      <td>Gulpen-Wittem</td>\n",
       "      <td>NaN</td>\n",
       "      <td>info@gulpen-wittem.nl 14 043</td>\n",
       "      <td>https://www.gulpen-wittem.nl/onderwerpen/verki...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM1729stembureaus20220316009</td>\n",
       "      <td>feb9d0a67a2f460f906d0d21e87bf690</td>\n",
       "      <td>2880.233287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>140000</th>\n",
       "      <td>E1920N3065</td>\n",
       "      <td>15</td>\n",
       "      <td>5</td>\n",
       "      <td>POINT (192250.000 306750.000)</td>\n",
       "      <td>151106</td>\n",
       "      <td>5276</td>\n",
       "      <td>29739</td>\n",
       "      <td>Gulpen-Wittem</td>\n",
       "      <td>GM1729</td>\n",
       "      <td>7</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gulpen-Wittem</td>\n",
       "      <td>Gulpen-Wittem</td>\n",
       "      <td>NaN</td>\n",
       "      <td>info@gulpen-wittem.nl 14 043</td>\n",
       "      <td>https://www.gulpen-wittem.nl/onderwerpen/verki...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM1729stembureaus20220316009</td>\n",
       "      <td>feb9d0a67a2f460f906d0d21e87bf690</td>\n",
       "      <td>2746.345509</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>140001</th>\n",
       "      <td>E1925N3065</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>POINT (192750.000 306750.000)</td>\n",
       "      <td>151107</td>\n",
       "      <td>5276</td>\n",
       "      <td>29739</td>\n",
       "      <td>Gulpen-Wittem</td>\n",
       "      <td>GM1729</td>\n",
       "      <td>7</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gulpen-Wittem</td>\n",
       "      <td>Gulpen-Wittem</td>\n",
       "      <td>NaN</td>\n",
       "      <td>info@gulpen-wittem.nl 14 043</td>\n",
       "      <td>https://www.gulpen-wittem.nl/onderwerpen/verki...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NLODSGM1729stembureaus20220316009</td>\n",
       "      <td>feb9d0a67a2f460f906d0d21e87bf690</td>\n",
       "      <td>2813.494018</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>140002 rows × 46 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       crs28992res500m  aantal_inwoners  stedelijkheid  \\\n",
       "0           E2270N6190                0         -99997   \n",
       "1           E2275N6190                0         -99997   \n",
       "2           E2280N6190                0         -99997   \n",
       "3           E2265N6185                0         -99997   \n",
       "4           E2270N6185                0         -99997   \n",
       "...                ...              ...            ...   \n",
       "139997      E1990N3070                0         -99997   \n",
       "139998      E1995N3070                0              5   \n",
       "139999      E1910N3065                0         -99997   \n",
       "140000      E1920N3065               15              5   \n",
       "140001      E1925N3065                0              5   \n",
       "\n",
       "                             geometry  savedindex  Unnamed: 0    _id  \\\n",
       "0       POINT (227250.000 619250.000)           2        5817  31030   \n",
       "1       POINT (227750.000 619250.000)           3        5817  31030   \n",
       "2       POINT (228250.000 619250.000)           4        5817  31030   \n",
       "3       POINT (226750.000 618750.000)           7        5817  31030   \n",
       "4       POINT (227250.000 618750.000)           8        5817  31030   \n",
       "...                               ...         ...         ...    ...   \n",
       "139997  POINT (199250.000 307250.000)      151102         498   4103   \n",
       "139998  POINT (199750.000 307250.000)      151103         498   4103   \n",
       "139999  POINT (191250.000 306750.000)      151105        5276  29739   \n",
       "140000  POINT (192250.000 306750.000)      151106        5276  29739   \n",
       "140001  POINT (192750.000 306750.000)      151107        5276  29739   \n",
       "\n",
       "             Gemeente CBS gemeentecode  Nummer stembureau  ...  \\\n",
       "0        Het Hogeland           GM1966                  1  ...   \n",
       "1        Het Hogeland           GM1966                  1  ...   \n",
       "2        Het Hogeland           GM1966                  1  ...   \n",
       "3        Het Hogeland           GM1966                  1  ...   \n",
       "4        Het Hogeland           GM1966                  1  ...   \n",
       "...               ...              ...                ...  ...   \n",
       "139997          Vaals           GM0981                  3  ...   \n",
       "139998          Vaals           GM0981                  3  ...   \n",
       "139999  Gulpen-Wittem           GM1729                  7  ...   \n",
       "140000  Gulpen-Wittem           GM1729                  7  ...   \n",
       "140001  Gulpen-Wittem           GM1729                  7  ...   \n",
       "\n",
       "       Gehandicaptentoilet   Kieskring ID Hoofdstembureau  Tellocatie  \\\n",
       "0                      NaN   Het Hogeland    Het Hogeland         NaN   \n",
       "1                      NaN   Het Hogeland    Het Hogeland         NaN   \n",
       "2                      NaN   Het Hogeland    Het Hogeland         NaN   \n",
       "3                      NaN   Het Hogeland    Het Hogeland         NaN   \n",
       "4                      NaN   Het Hogeland    Het Hogeland         NaN   \n",
       "...                    ...            ...             ...         ...   \n",
       "139997                 NaN          Vaals           Vaals         NaN   \n",
       "139998                 NaN          Vaals           Vaals         NaN   \n",
       "139999                 NaN  Gulpen-Wittem   Gulpen-Wittem         NaN   \n",
       "140000                 NaN  Gulpen-Wittem   Gulpen-Wittem         NaN   \n",
       "140001                 NaN  Gulpen-Wittem   Gulpen-Wittem         NaN   \n",
       "\n",
       "                            Contactgegevens gemeente  \\\n",
       "0                        verkiezingen@hethogeland.nl   \n",
       "1                        verkiezingen@hethogeland.nl   \n",
       "2                        verkiezingen@hethogeland.nl   \n",
       "3                        verkiezingen@hethogeland.nl   \n",
       "4                        verkiezingen@hethogeland.nl   \n",
       "...                                              ...   \n",
       "139997  Team verkiezingen, verkiezingen2022@vaals.nl   \n",
       "139998  Team verkiezingen, verkiezingen2022@vaals.nl   \n",
       "139999                  info@gulpen-wittem.nl 14 043   \n",
       "140000                  info@gulpen-wittem.nl 14 043   \n",
       "140001                  info@gulpen-wittem.nl 14 043   \n",
       "\n",
       "                              Verkiezingswebsite gemeente  Verkiezingen  \\\n",
       "0       https://hethogeland.nl/bestuur-en-organisatie/...           NaN   \n",
       "1       https://hethogeland.nl/bestuur-en-organisatie/...           NaN   \n",
       "2       https://hethogeland.nl/bestuur-en-organisatie/...           NaN   \n",
       "3       https://hethogeland.nl/bestuur-en-organisatie/...           NaN   \n",
       "4       https://hethogeland.nl/bestuur-en-organisatie/...           NaN   \n",
       "...                                                   ...           ...   \n",
       "139997                   http://www.vaals.nl/verkiezingen           NaN   \n",
       "139998                   http://www.vaals.nl/verkiezingen           NaN   \n",
       "139999  https://www.gulpen-wittem.nl/onderwerpen/verki...           NaN   \n",
       "140000  https://www.gulpen-wittem.nl/onderwerpen/verki...           NaN   \n",
       "140001  https://www.gulpen-wittem.nl/onderwerpen/verki...           NaN   \n",
       "\n",
       "                                       ID                              UUID  \\\n",
       "0       NLODSGM1966stembureaus20220316009  6df04b8dd4be4aa3b4a03f221ab5ad17   \n",
       "1       NLODSGM1966stembureaus20220316009  6df04b8dd4be4aa3b4a03f221ab5ad17   \n",
       "2       NLODSGM1966stembureaus20220316009  6df04b8dd4be4aa3b4a03f221ab5ad17   \n",
       "3       NLODSGM1966stembureaus20220316009  6df04b8dd4be4aa3b4a03f221ab5ad17   \n",
       "4       NLODSGM1966stembureaus20220316009  6df04b8dd4be4aa3b4a03f221ab5ad17   \n",
       "...                                   ...                               ...   \n",
       "139997  NLODSGM0981stembureaus20220316009  3dfcfccd163145698a33b19623c5c3f3   \n",
       "139998  NLODSGM0981stembureaus20220316009  3dfcfccd163145698a33b19623c5c3f3   \n",
       "139999  NLODSGM1729stembureaus20220316009  feb9d0a67a2f460f906d0d21e87bf690   \n",
       "140000  NLODSGM1729stembureaus20220316009  feb9d0a67a2f460f906d0d21e87bf690   \n",
       "140001  NLODSGM1729stembureaus20220316009  feb9d0a67a2f460f906d0d21e87bf690   \n",
       "\n",
       "                dist  \n",
       "0       17236.920436  \n",
       "1       17280.014918  \n",
       "2       17337.427867  \n",
       "3       16708.725120  \n",
       "4       16738.249149  \n",
       "...              ...  \n",
       "139997   2010.126740  \n",
       "139998   1949.951758  \n",
       "139999   2880.233287  \n",
       "140000   2746.345509  \n",
       "140001   2813.494018  \n",
       "\n",
       "[140002 rows x 46 columns]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nl_map_dst_zero_points[\"aantal_inwoners\"].mask(nl_map_dst_zero_points[\"aantal_inwoners\"] == -99997, 0, inplace=True)\n",
    "nl_map_dst_zero_points.head()\n",
    "df_nearest_zero = ckdnearest(nl_map_dst_zero_points.to_crs(epsg=28992), gdf_wims_dedupe.to_crs(epsg=28992))\n",
    "df_nearest_zero[\"aantal_inwoners\"].dropna()\n",
    "df_nearest_zero[\"dist\"].dropna()\n",
    "df_nearest_zero"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Gemeente</th>\n",
       "      <th>Naam stembureau</th>\n",
       "      <th>dist</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>47304</th>\n",
       "      <td>Ridderkerk</td>\n",
       "      <td>Gemeentehuis</td>\n",
       "      <td>3.835321</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32815</th>\n",
       "      <td>Baarn</td>\n",
       "      <td>Dorpshuis de Furs</td>\n",
       "      <td>4.000517</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5168</th>\n",
       "      <td>Groningen</td>\n",
       "      <td>Dorpshuis De Hoeksteen</td>\n",
       "      <td>5.577246</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38975</th>\n",
       "      <td>Montfoort</td>\n",
       "      <td>Zalencentrum St. Joseph</td>\n",
       "      <td>5.703409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67518</th>\n",
       "      <td>Kerkrade</td>\n",
       "      <td>’t Westhoes</td>\n",
       "      <td>7.252446</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23422</th>\n",
       "      <td>Zeewolde</td>\n",
       "      <td>Het Kruispunt</td>\n",
       "      <td>8207.619943</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22478</th>\n",
       "      <td>Lelystad</td>\n",
       "      <td>Gymzaal De Borg</td>\n",
       "      <td>8402.730770</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22348</th>\n",
       "      <td>Lelystad</td>\n",
       "      <td>Voormalige Scholengemeenschap De Rietlanden</td>\n",
       "      <td>8540.805874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22477</th>\n",
       "      <td>Lelystad</td>\n",
       "      <td>Voormalige Scholengemeenschap De Rietlanden</td>\n",
       "      <td>9028.790070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22619</th>\n",
       "      <td>Zeewolde</td>\n",
       "      <td>Panta Rhei</td>\n",
       "      <td>9173.600947</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68131 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Gemeente                              Naam stembureau         dist\n",
       "47304  Ridderkerk                                 Gemeentehuis     3.835321\n",
       "32815       Baarn                            Dorpshuis de Furs     4.000517\n",
       "5168    Groningen                       Dorpshuis De Hoeksteen     5.577246\n",
       "38975   Montfoort                      Zalencentrum St. Joseph     5.703409\n",
       "67518    Kerkrade                                  ’t Westhoes     7.252446\n",
       "...           ...                                          ...          ...\n",
       "23422    Zeewolde                                Het Kruispunt  8207.619943\n",
       "22478    Lelystad                              Gymzaal De Borg  8402.730770\n",
       "22348    Lelystad  Voormalige Scholengemeenschap De Rietlanden  8540.805874\n",
       "22477    Lelystad  Voormalige Scholengemeenschap De Rietlanden  9028.790070\n",
       "22619    Zeewolde                                   Panta Rhei  9173.600947\n",
       "\n",
       "[68131 rows x 3 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_nearest.sort_values(by=['dist'], inplace=True)\n",
    "df_nearest[['Gemeente', 'Naam stembureau', 'dist']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_dist(df, label):\n",
    "    plt.figure(figsize=(13,13))\n",
    "    df['dist'].plot(kind=\"hist\", weights=df['aantal_inwoners'], figsize=(13,13), fontsize=22, 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)')\n",
    "    plt.figure(figsize=(13,13))\n",
    "    df.plot.scatter(x = 'aantal_inwoners', y = 'dist', figsize=(13,13), fontsize=22, 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)\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 73556 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "ax_nearest_zero = df_nearest_zero.plot.scatter(x = 'aantal_inwoners', y = 'dist', figsize=(13,13), fontsize=22, xlabel=\"Inwoners per 500m² (inclusief lege (<5 inwoners) vierkanten)\", ylabel=\"Afstand tot stemlokaal (meter)\")\n",
    "\n",
    "\n",
    "ax_nearest_zero.set_xscale('log')\n",
    "#ax_nearest_zero.set_yscale('log')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "FIGSIZE = (13, 13)\n",
    "def plot_bargraph_with_groupings(df, groupby, colourby, title, xlabel, ylabel):\n",
    "\n",
    "    import matplotlib.patches as mpatches\n",
    "\n",
    "\n",
    "    # Makes the bargraph.\n",
    "    ax = df[groupby].value_counts().plot(kind='bar',\n",
    "                                         figsize=FIGSIZE,\n",
    "                                         title=title)\n",
    "    \n",
    "\n",
    "    # display the graph.\n",
    "    \n",
    "    ax.set_xlabel(xlabel)\n",
    "    ax.set_ylabel(ylabel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 274148 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_bargraph_with_groupings(gdf_wims_dedupe, 'Gebruiksdoel van het gebouw', 'Gemeente', 'Gebruiksdoelen van Stemlokalen', 'Gebruiksdoel', 'Hoeveelheid Stemlokalen')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Dit is onbruikbaar, de categorieën moeten elk één balkje zijn, niet zoals dit."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_use (df, label):\n",
    "    plt.figure(figsize=(13,13))\n",
    "    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'))\n",
    "    #print(df_exploded)\n",
    "    plot_bargraph_with_groupings(df_exploded, 'Gebruiksdoel van het gebouw', 'Gemeente', 'Gebruiksdoelen van Stemlokalen Staffel {}'.format(label), 'Gebruiksdoel', 'Hoeveelheid Stemlokalen')\n",
    "    print(\"Staffel: {}\".format(label))\n",
    "    print(df_exploded['Gebruiksdoel van het gebouw'].value_counts())\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Amsterdam              456\n",
       "Rotterdam              398\n",
       "'s-Gravenhage          271\n",
       "Utrecht                162\n",
       "Breda                   90\n",
       "Eindhoven               86\n",
       "Groningen               85\n",
       "Apeldoorn               71\n",
       "Enschede                69\n",
       "Alphen aan den Rijn     66\n",
       "Leiden                  52\n",
       "Deventer                51\n",
       "West Betuwe             37\n",
       "Waadhoeke               33\n",
       "Amsterdam              382\n",
       "Rotterdam              375\n",
       "'s-Gravenhage          258\n",
       "Utrecht                161\n",
       "Groningen              122\n",
       "Breda                   89\n",
       "Haarlemmermeer          79\n",
       "Nijmegen                74\n",
       "'s-Hertogenbosch        40\n",
       "Het Hogeland            39\n",
       "Zoetermeer              38\n",
       "Staphorst                2\n",
       "Name: Gemeente, dtype: int64"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "wims_count = gdf_wims_dedupe['Gemeente'].value_counts()\n",
    "\n",
    "\n",
    "geojson_rename = df_geojson_dedupe.rename(columns = {'electionName': 'Gemeente'})\n",
    "geojson_count = geojson_rename['Gemeente'].str.slice(13, -5).value_counts()\n",
    "\n",
    "pd.concat([geojson_count, wims_count]).drop_duplicates(keep=False)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "standard_14 = '2022-03-14T07:30:00 tot 2022-03-14T21:00:00'\n",
    "standard_15 = '2022-03-15T07:30:00 tot 2022-03-15T21:00:00'\n",
    "standard_16 = '2022-03-16T07:30:00 tot 2022-03-16T21:00:00'\n",
    "\n",
    "\n",
    "nan_value = float(\"NaN\")\n",
    "gdf_wims_dedupe.replace(\" \", nan_value, inplace = True)\n",
    "gdf_wims_dedupe.replace(\"  \", nan_value, inplace = True)\n",
    "\n",
    "wims_nonstandaard_14 = gdf_wims_dedupe.dropna(subset=['Openingstijden 14-03-2022']).loc[gdf_wims_dedupe['Openingstijden 14-03-2022'] != standard_14]\n",
    "wims_nonstandaard_15 = gdf_wims_dedupe.dropna(subset=['Openingstijden 15-03-2022']).loc[gdf_wims_dedupe['Openingstijden 15-03-2022'] != standard_15]\n",
    "wims_nonstandaard_16 = gdf_wims_dedupe.dropna(subset=['Openingstijden 16-03-2022']).loc[gdf_wims_dedupe['Openingstijden 16-03-2022'] != standard_16]\n",
    "wims_standaard_14 = gdf_wims_dedupe.loc[gdf_wims_dedupe['Openingstijden 14-03-2022'] == standard_14]\n",
    "wims_standaard_15 = gdf_wims_dedupe.loc[gdf_wims_dedupe['Openingstijden 15-03-2022'] == standard_15]\n",
    "wims_standaard_16 = gdf_wims_dedupe.loc[gdf_wims_dedupe['Openingstijden 16-03-2022'] == standard_16]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Openingstijden 14-03-2022</th>\n",
       "      <th>Openingstijden 15-03-2022</th>\n",
       "      <th>Openingstijden 16-03-2022</th>\n",
       "      <th>UUID</th>\n",
       "      <th>Gemeente</th>\n",
       "      <th>CBS gemeentecode</th>\n",
       "      <th>Openingstijden 14-03-2022 van</th>\n",
       "      <th>Openingstijden 14-03-2022 tot</th>\n",
       "      <th>Openingstijden 15-03-2022 van</th>\n",
       "      <th>Openingstijden 15-03-2022 tot</th>\n",
       "      <th>Openingstijden 16-03-2022 van</th>\n",
       "      <th>Openingstijden 16-03-2022 tot</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T10:00:00 tot 2022-03-16T13:00:00</td>\n",
       "      <td>3a612b2151fa4ab491b9e331355e6258</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T10:00:00</td>\n",
       "      <td>2022-03-16T13:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>9a01d765af0a467ea37f08d92db114ba</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00</td>\n",
       "      <td>2022-03-16T21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>fc5869d33fbc4b06be659149fa615f4c</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00</td>\n",
       "      <td>2022-03-16T21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>4427cc0b39e040ba8f75c333f19d66f0</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00</td>\n",
       "      <td>2022-03-16T21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-03-14T07:30:00 tot 2022-03-14T21:00:00</td>\n",
       "      <td>2022-03-15T07:30:00 tot 2022-03-15T21:00:00</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>a893bb9add324ce29769f1c39afcc48d</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>2022-03-14T07:30:00</td>\n",
       "      <td>2022-03-14T21:00:00</td>\n",
       "      <td>2022-03-15T07:30:00</td>\n",
       "      <td>2022-03-15T21:00:00</td>\n",
       "      <td>2022-03-16T07:30:00</td>\n",
       "      <td>2022-03-16T21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9270</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>f744546cd6894e5e9a4db4bbfd81b4ee</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00</td>\n",
       "      <td>2022-03-16T21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9271</th>\n",
       "      <td>2022-03-14T07:30:00 tot 2022-03-14T21:00:00</td>\n",
       "      <td>2022-03-15T07:30:00 tot 2022-03-15T21:00:00</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>1270081b1dc74cd7bea0f45973650408</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>2022-03-14T07:30:00</td>\n",
       "      <td>2022-03-14T21:00:00</td>\n",
       "      <td>2022-03-15T07:30:00</td>\n",
       "      <td>2022-03-15T21:00:00</td>\n",
       "      <td>2022-03-16T07:30:00</td>\n",
       "      <td>2022-03-16T21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9272</th>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-15T07:30:00 tot 2022-03-15T21:00:00</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>447c7742604345139e41def4cf1e4d3c</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-15T07:30:00</td>\n",
       "      <td>2022-03-15T21:00:00</td>\n",
       "      <td>2022-03-16T07:30:00</td>\n",
       "      <td>2022-03-16T21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9273</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>049cfd258c174bc49abf17883396d083</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00</td>\n",
       "      <td>2022-03-16T21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9274</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>1e8cbe96e72c4c6ba6303f47bec8cdb5</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00</td>\n",
       "      <td>2022-03-16T21:00:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8089 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                        Openingstijden 14-03-2022  \\\n",
       "0                                             NaN   \n",
       "1                                             NaN   \n",
       "2                                             NaN   \n",
       "3                                             NaN   \n",
       "4     2022-03-14T07:30:00 tot 2022-03-14T21:00:00   \n",
       "...                                           ...   \n",
       "9270                                          NaN   \n",
       "9271  2022-03-14T07:30:00 tot 2022-03-14T21:00:00   \n",
       "9272                                          NaN   \n",
       "9273                                          NaN   \n",
       "9274                                          NaN   \n",
       "\n",
       "                        Openingstijden 15-03-2022  \\\n",
       "0                                             NaN   \n",
       "1                                             NaN   \n",
       "2                                             NaN   \n",
       "3                                             NaN   \n",
       "4     2022-03-15T07:30:00 tot 2022-03-15T21:00:00   \n",
       "...                                           ...   \n",
       "9270                                          NaN   \n",
       "9271  2022-03-15T07:30:00 tot 2022-03-15T21:00:00   \n",
       "9272  2022-03-15T07:30:00 tot 2022-03-15T21:00:00   \n",
       "9273                                          NaN   \n",
       "9274                                          NaN   \n",
       "\n",
       "                        Openingstijden 16-03-2022  \\\n",
       "0     2022-03-16T10:00:00 tot 2022-03-16T13:00:00   \n",
       "1     2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "2     2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "3     2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "4     2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "...                                           ...   \n",
       "9270  2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "9271  2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "9272  2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "9273  2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "9274  2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "\n",
       "                                  UUID      Gemeente CBS gemeentecode  \\\n",
       "0     3a612b2151fa4ab491b9e331355e6258  Valkenswaard           GM0858   \n",
       "1     9a01d765af0a467ea37f08d92db114ba  Valkenswaard           GM0858   \n",
       "2     fc5869d33fbc4b06be659149fa615f4c  Valkenswaard           GM0858   \n",
       "3     4427cc0b39e040ba8f75c333f19d66f0  Valkenswaard           GM0858   \n",
       "4     a893bb9add324ce29769f1c39afcc48d  Valkenswaard           GM0858   \n",
       "...                                ...           ...              ...   \n",
       "9270  f744546cd6894e5e9a4db4bbfd81b4ee        Gennep           GM0907   \n",
       "9271  1270081b1dc74cd7bea0f45973650408        Gennep           GM0907   \n",
       "9272  447c7742604345139e41def4cf1e4d3c        Gennep           GM0907   \n",
       "9273  049cfd258c174bc49abf17883396d083        Gennep           GM0907   \n",
       "9274  1e8cbe96e72c4c6ba6303f47bec8cdb5        Gennep           GM0907   \n",
       "\n",
       "     Openingstijden 14-03-2022 van Openingstijden 14-03-2022 tot  \\\n",
       "0                              NaN                           NaN   \n",
       "1                              NaN                           NaN   \n",
       "2                              NaN                           NaN   \n",
       "3                              NaN                           NaN   \n",
       "4              2022-03-14T07:30:00           2022-03-14T21:00:00   \n",
       "...                            ...                           ...   \n",
       "9270                           NaN                           NaN   \n",
       "9271           2022-03-14T07:30:00           2022-03-14T21:00:00   \n",
       "9272                           NaN                           NaN   \n",
       "9273                           NaN                           NaN   \n",
       "9274                           NaN                           NaN   \n",
       "\n",
       "     Openingstijden 15-03-2022 van Openingstijden 15-03-2022 tot  \\\n",
       "0                              NaN                           NaN   \n",
       "1                              NaN                           NaN   \n",
       "2                              NaN                           NaN   \n",
       "3                              NaN                           NaN   \n",
       "4              2022-03-15T07:30:00           2022-03-15T21:00:00   \n",
       "...                            ...                           ...   \n",
       "9270                           NaN                           NaN   \n",
       "9271           2022-03-15T07:30:00           2022-03-15T21:00:00   \n",
       "9272           2022-03-15T07:30:00           2022-03-15T21:00:00   \n",
       "9273                           NaN                           NaN   \n",
       "9274                           NaN                           NaN   \n",
       "\n",
       "     Openingstijden 16-03-2022 van Openingstijden 16-03-2022 tot  \n",
       "0              2022-03-16T10:00:00           2022-03-16T13:00:00  \n",
       "1              2022-03-16T07:30:00           2022-03-16T21:00:00  \n",
       "2              2022-03-16T07:30:00           2022-03-16T21:00:00  \n",
       "3              2022-03-16T07:30:00           2022-03-16T21:00:00  \n",
       "4              2022-03-16T07:30:00           2022-03-16T21:00:00  \n",
       "...                            ...                           ...  \n",
       "9270           2022-03-16T07:30:00           2022-03-16T21:00:00  \n",
       "9271           2022-03-16T07:30:00           2022-03-16T21:00:00  \n",
       "9272           2022-03-16T07:30:00           2022-03-16T21:00:00  \n",
       "9273           2022-03-16T07:30:00           2022-03-16T21:00:00  \n",
       "9274           2022-03-16T07:30:00           2022-03-16T21:00:00  \n",
       "\n",
       "[8089 rows x 12 columns]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdf_wims_times = gdf_wims_dedupe.loc[:, ('Openingstijden 14-03-2022','Openingstijden 15-03-2022','Openingstijden 16-03-2022', 'UUID', 'Gemeente', 'CBS gemeentecode')]\n",
    "gdf_wims_split = gdf_wims_times\n",
    "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)\n",
    "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)\n",
    "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)\n",
    "\n",
    "gdf_wims_split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Openingstijden 14-03-2022</th>\n",
       "      <th>Openingstijden 15-03-2022</th>\n",
       "      <th>Openingstijden 16-03-2022</th>\n",
       "      <th>UUID</th>\n",
       "      <th>Gemeente</th>\n",
       "      <th>CBS gemeentecode</th>\n",
       "      <th>Openingstijden 14-03-2022 van</th>\n",
       "      <th>Openingstijden 14-03-2022 tot</th>\n",
       "      <th>Openingstijden 15-03-2022 van</th>\n",
       "      <th>Openingstijden 15-03-2022 tot</th>\n",
       "      <th>Openingstijden 16-03-2022 van</th>\n",
       "      <th>Openingstijden 16-03-2022 tot</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T10:00:00 tot 2022-03-16T13:00:00</td>\n",
       "      <td>3a612b2151fa4ab491b9e331355e6258</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>2022-03-16 10:00:00</td>\n",
       "      <td>2022-03-16 13:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>9a01d765af0a467ea37f08d92db114ba</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>2022-03-16 07:30:00</td>\n",
       "      <td>2022-03-16 21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>fc5869d33fbc4b06be659149fa615f4c</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>2022-03-16 07:30:00</td>\n",
       "      <td>2022-03-16 21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>4427cc0b39e040ba8f75c333f19d66f0</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>2022-03-16 07:30:00</td>\n",
       "      <td>2022-03-16 21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-03-14T07:30:00 tot 2022-03-14T21:00:00</td>\n",
       "      <td>2022-03-15T07:30:00 tot 2022-03-15T21:00:00</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>a893bb9add324ce29769f1c39afcc48d</td>\n",
       "      <td>Valkenswaard</td>\n",
       "      <td>GM0858</td>\n",
       "      <td>2022-03-14 07:30:00</td>\n",
       "      <td>2022-03-14 21:00:00</td>\n",
       "      <td>2022-03-15 07:30:00</td>\n",
       "      <td>2022-03-15 21:00:00</td>\n",
       "      <td>2022-03-16 07:30:00</td>\n",
       "      <td>2022-03-16 21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9270</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>f744546cd6894e5e9a4db4bbfd81b4ee</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>2022-03-16 07:30:00</td>\n",
       "      <td>2022-03-16 21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9271</th>\n",
       "      <td>2022-03-14T07:30:00 tot 2022-03-14T21:00:00</td>\n",
       "      <td>2022-03-15T07:30:00 tot 2022-03-15T21:00:00</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>1270081b1dc74cd7bea0f45973650408</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>2022-03-14 07:30:00</td>\n",
       "      <td>2022-03-14 21:00:00</td>\n",
       "      <td>2022-03-15 07:30:00</td>\n",
       "      <td>2022-03-15 21:00:00</td>\n",
       "      <td>2022-03-16 07:30:00</td>\n",
       "      <td>2022-03-16 21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9272</th>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-15T07:30:00 tot 2022-03-15T21:00:00</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>447c7742604345139e41def4cf1e4d3c</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>2022-03-15 07:30:00</td>\n",
       "      <td>2022-03-15 21:00:00</td>\n",
       "      <td>2022-03-16 07:30:00</td>\n",
       "      <td>2022-03-16 21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9273</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>049cfd258c174bc49abf17883396d083</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>2022-03-16 07:30:00</td>\n",
       "      <td>2022-03-16 21:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9274</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022-03-16T07:30:00 tot 2022-03-16T21:00:00</td>\n",
       "      <td>1e8cbe96e72c4c6ba6303f47bec8cdb5</td>\n",
       "      <td>Gennep</td>\n",
       "      <td>GM0907</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaT</td>\n",
       "      <td>2022-03-16 07:30:00</td>\n",
       "      <td>2022-03-16 21:00:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8089 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                        Openingstijden 14-03-2022  \\\n",
       "0                                             NaN   \n",
       "1                                             NaN   \n",
       "2                                             NaN   \n",
       "3                                             NaN   \n",
       "4     2022-03-14T07:30:00 tot 2022-03-14T21:00:00   \n",
       "...                                           ...   \n",
       "9270                                          NaN   \n",
       "9271  2022-03-14T07:30:00 tot 2022-03-14T21:00:00   \n",
       "9272                                          NaN   \n",
       "9273                                          NaN   \n",
       "9274                                          NaN   \n",
       "\n",
       "                        Openingstijden 15-03-2022  \\\n",
       "0                                             NaN   \n",
       "1                                             NaN   \n",
       "2                                             NaN   \n",
       "3                                             NaN   \n",
       "4     2022-03-15T07:30:00 tot 2022-03-15T21:00:00   \n",
       "...                                           ...   \n",
       "9270                                          NaN   \n",
       "9271  2022-03-15T07:30:00 tot 2022-03-15T21:00:00   \n",
       "9272  2022-03-15T07:30:00 tot 2022-03-15T21:00:00   \n",
       "9273                                          NaN   \n",
       "9274                                          NaN   \n",
       "\n",
       "                        Openingstijden 16-03-2022  \\\n",
       "0     2022-03-16T10:00:00 tot 2022-03-16T13:00:00   \n",
       "1     2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "2     2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "3     2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "4     2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "...                                           ...   \n",
       "9270  2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "9271  2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "9272  2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "9273  2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "9274  2022-03-16T07:30:00 tot 2022-03-16T21:00:00   \n",
       "\n",
       "                                  UUID      Gemeente CBS gemeentecode  \\\n",
       "0     3a612b2151fa4ab491b9e331355e6258  Valkenswaard           GM0858   \n",
       "1     9a01d765af0a467ea37f08d92db114ba  Valkenswaard           GM0858   \n",
       "2     fc5869d33fbc4b06be659149fa615f4c  Valkenswaard           GM0858   \n",
       "3     4427cc0b39e040ba8f75c333f19d66f0  Valkenswaard           GM0858   \n",
       "4     a893bb9add324ce29769f1c39afcc48d  Valkenswaard           GM0858   \n",
       "...                                ...           ...              ...   \n",
       "9270  f744546cd6894e5e9a4db4bbfd81b4ee        Gennep           GM0907   \n",
       "9271  1270081b1dc74cd7bea0f45973650408        Gennep           GM0907   \n",
       "9272  447c7742604345139e41def4cf1e4d3c        Gennep           GM0907   \n",
       "9273  049cfd258c174bc49abf17883396d083        Gennep           GM0907   \n",
       "9274  1e8cbe96e72c4c6ba6303f47bec8cdb5        Gennep           GM0907   \n",
       "\n",
       "     Openingstijden 14-03-2022 van Openingstijden 14-03-2022 tot  \\\n",
       "0                              NaT                           NaT   \n",
       "1                              NaT                           NaT   \n",
       "2                              NaT                           NaT   \n",
       "3                              NaT                           NaT   \n",
       "4              2022-03-14 07:30:00           2022-03-14 21:00:00   \n",
       "...                            ...                           ...   \n",
       "9270                           NaT                           NaT   \n",
       "9271           2022-03-14 07:30:00           2022-03-14 21:00:00   \n",
       "9272                           NaT                           NaT   \n",
       "9273                           NaT                           NaT   \n",
       "9274                           NaT                           NaT   \n",
       "\n",
       "     Openingstijden 15-03-2022 van Openingstijden 15-03-2022 tot  \\\n",
       "0                              NaT                           NaT   \n",
       "1                              NaT                           NaT   \n",
       "2                              NaT                           NaT   \n",
       "3                              NaT                           NaT   \n",
       "4              2022-03-15 07:30:00           2022-03-15 21:00:00   \n",
       "...                            ...                           ...   \n",
       "9270                           NaT                           NaT   \n",
       "9271           2022-03-15 07:30:00           2022-03-15 21:00:00   \n",
       "9272           2022-03-15 07:30:00           2022-03-15 21:00:00   \n",
       "9273                           NaT                           NaT   \n",
       "9274                           NaT                           NaT   \n",
       "\n",
       "     Openingstijden 16-03-2022 van Openingstijden 16-03-2022 tot  \n",
       "0              2022-03-16 10:00:00           2022-03-16 13:00:00  \n",
       "1              2022-03-16 07:30:00           2022-03-16 21:00:00  \n",
       "2              2022-03-16 07:30:00           2022-03-16 21:00:00  \n",
       "3              2022-03-16 07:30:00           2022-03-16 21:00:00  \n",
       "4              2022-03-16 07:30:00           2022-03-16 21:00:00  \n",
       "...                            ...                           ...  \n",
       "9270           2022-03-16 07:30:00           2022-03-16 21:00:00  \n",
       "9271           2022-03-16 07:30:00           2022-03-16 21:00:00  \n",
       "9272           2022-03-16 07:30:00           2022-03-16 21:00:00  \n",
       "9273           2022-03-16 07:30:00           2022-03-16 21:00:00  \n",
       "9274           2022-03-16 07:30:00           2022-03-16 21:00:00  \n",
       "\n",
       "[8089 rows x 12 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "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')\n",
    "gdf_wims_split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "import datetime as dt\n",
    "import numpy as np\n",
    "\n",
    "def datesplit(df, column):\n",
    "\n",
    "    df = df.dropna(subset = ['{} van'.format(column)])\n",
    "    df1 = df.rename(columns={'{} van'.format(column):'vandate','{} tot'.format(column):'totdate', 'UUID':'UUID'})\n",
    "    return  (pd.concat([pd.Series(r.UUID,pd.date_range(r.vandate, r.totdate, freq='0.5H')) \n",
    "                        for r in df1.itertuples()])\n",
    "               .rename_axis('Openingstijden')\n",
    "               .reset_index(name='UUID'))\n",
    "def plot_opening(df, label):\n",
    "    print(\"Open op 14 maart groep {}: {}\".format(label, df[df['Openingstijden 15-03-2022 van'].isnull()][df['Openingstijden 16-03-2022 van'].isnull()]['Openingstijden 14-03-2022 van'].count()))\n",
    "    print(\"Open op 15 maart groep {}: {}\".format(label, df[df['Openingstijden 14-03-2022 van'].isnull()][df['Openingstijden 16-03-2022 van'].isnull()]['Openingstijden 15-03-2022 van'].count()))\n",
    "    print(\"Open op 16 maart groep {}: {}\".format(label, df[df['Openingstijden 14-03-2022 van'].isnull()][df['Openingstijden 15-03-2022 van'].isnull()]['Openingstijden 16-03-2022 van'].count()))\n",
    "\n",
    "    print(\"Open op 14 én 15 maart groep {}: {}\".format(label, df[df['Openingstijden 16-03-2022 van'].isnull()].dropna(subset=['Openingstijden 15-03-2022 van'])['Openingstijden 14-03-2022 van'].count()))\n",
    "    print(\"Open op 14 én 16 maart groep {}: {}\".format(label, df[df['Openingstijden 15-03-2022 van'].isnull()].dropna(subset=['Openingstijden 16-03-2022 van'])['Openingstijden 14-03-2022 van'].count()))\n",
    "    print(\"Open op 15 én 16 maart groep {}: {}\".format(label, df[df['Openingstijden 14-03-2022 van'].isnull()].dropna(subset=['Openingstijden 15-03-2022 van'])['Openingstijden 16-03-2022 van'].count()))\n",
    "    print(\"Open op 14, 15 én 16 maart groep {}: {}\".format(label, df.dropna(subset=['Openingstijden 16-03-2022 van', 'Openingstijden 15-03-2022 van'])['Openingstijden 14-03-2022 van'].count()))\n",
    "\n",
    "    opening = np.datetime64('2022-03-16 07:30:00')\n",
    "    closing = np.datetime64('2022-03-16 21:00:00')\n",
    "\n",
    "    #print(df[(df['Openingstijden 16-03-2022 van'] == opening)])\n",
    "    df_standard = df[(df['Openingstijden 16-03-2022 van'] == opening) & (df['Openingstijden 16-03-2022 tot'] == closing)]\n",
    "\n",
    "    print(\"Aantal stemlokalen open op standaard tijden 16 Maart in staffel {}: {}\".format(label, df_standard['Openingstijden 14-03-2022 van'].count()))\n",
    "\n",
    "    plt.figure(figsize=(13,13))\n",
    "    wims_datesplit_14 = df.loc[:, ('Openingstijden 14-03-2022 van','Openingstijden 14-03-2022 tot', 'UUID')]\n",
    "    wims_datesplit_15 = df.loc[:, ('Openingstijden 15-03-2022 van','Openingstijden 15-03-2022 tot', 'UUID')]\n",
    "    wims_datesplit_16 = df.loc[:, ('Openingstijden 16-03-2022 van','Openingstijden 16-03-2022 tot', 'UUID')]\n",
    "    wims_datesplit_14 = datesplit(wims_datesplit_14, 'Openingstijden 14-03-2022')\n",
    "    wims_datesplit_15 = datesplit(wims_datesplit_15, 'Openingstijden 15-03-2022')\n",
    "    wims_datesplit_16 = datesplit(wims_datesplit_16, 'Openingstijden 16-03-2022')\n",
    "\n",
    "    wims_datesplit_14.reset_index()\n",
    "    wims_datesplit_15.reset_index()\n",
    "    wims_datesplit_16.reset_index()\n",
    "\n",
    "    #wims_datesplit_14.info()\n",
    "    #wims_datesplit_15.info()\n",
    "    #wims_datesplit_16.info()\n",
    "\n",
    "    \n",
    "    wims_datestack = pd.concat([wims_datesplit_14, wims_datesplit_15], ignore_index=True)\n",
    "    wims_datestack = pd.concat([wims_datestack, wims_datesplit_16], ignore_index=True)\n",
    "    \n",
    "    wims_datestack.set_index('Openingstijden', drop=False, inplace=True)\n",
    "\n",
    "    #print(wims_datestack['Openingstijden'].unique())\n",
    "\n",
    "    xticks = []\n",
    "    xticklabels = []\n",
    "    datetimecount = 0\n",
    "    for datetime in wims_datestack.groupby(pd.Grouper(freq='30Min'))['Openingstijden'].unique():\n",
    "        if (datetime.size > 0):\n",
    "            xticks.append(datetime.ravel()[0])\n",
    "            if(datetimecount % 6 == 0):\n",
    "                ts = pd.to_datetime(datetime.ravel()[0])\n",
    "                #hardcoded for the data, sloppy code, quick fix, only applies to timestamps with 7 minute changes to reality\n",
    "                if (ts.minute == 7):\n",
    "                    ts = ts - dt.timedelta(minutes=7)\n",
    "                xticklabels.append(ts.strftime(\"%m-%d %H:%M\"))\n",
    "            else:\n",
    "                xticklabels.append(\" \")\n",
    "        else:\n",
    "            xticks.append(\"\")\n",
    "            xticklabels.append(\"\")\n",
    "        datetimecount += 1\n",
    "\n",
    "\n",
    "    wims_datestack.groupby(pd.Grouper(freq='30Min')).count().plot(kind='bar', y='Openingstijden',width=1, figsize=(25, 25), title=\"Openingstijden stemlokalen staffel {}\".format(label), log=True).set_xticklabels(xticklabels, rotation=-45, ha=\"left\", rotation_mode=\"anchor\")\n",
    "    \n",
    "\n",
    "    \n",
    "    dfg = wims_datestack.groupby(pd.Grouper(freq='30Min')).count()\n",
    "    dfg['Staffel'] = label\n",
    "\n",
    "    global wims_datestack_grouped\n",
    "    if (label != 'totaal'):\n",
    "        wims_datestack_grouped = pd.concat([wims_datestack_grouped, dfg])\n",
    "    wims_datestack.to_csv(path_or_buf='../data/export/openingstijden_staffel_{}.csv'.format(label), sep=';', na_rep='', header=True, date_format = '%m-%d %H:%M')\n",
    "\n",
    "\n",
    "    #wims_datesplit_16.groupby(wims_datesplit_16[\"Openingstijden 16-03-2022\"].dt.hour).count().plot(kind=\"bar\", y='Openingstijden 16-03-2022')\n",
    "    #wims_datesplit_16.groupby(pd.Grouper(freq='30Min')).count().plot(kind='bar', y='Openingstijden 16-03-2022')\n",
    "    #wims_datesplit_15.groupby(wims_datesplit_15[\"Openingstijden 15-03-2022\"].dt.hour).count().plot(kind=\"bar\", y='Openingstijden 15-03-2022')\n",
    "    #wims_datesplit_14.groupby(wims_datesplit_14[\"Openingstijden 14-03-2022\"].dt.hour).count().plot(kind=\"bar\", y='Openingstijden 14-03-2022')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "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])\n",
    "df_stemger_clean = df_stemger[df_stemger['gemeentecode'].isin(nl_map_clean['GM_CODE'])]\n",
    "\n",
    "bins = [0, 10, 30, 60, 100, 350, float(\"inf\")]\n",
    "labels = ['1; 0-10.000 stemgerechtigden', '2; 10.000-30.000 stemgerechtigden', '3; 30.000-60.000 stemgerechtigden', '4; 60.000-100.000 stemgerechtigden', '5; 100.000-350.000 stemgerechtigden', '6; >350.000 stemgerechtigden']\n",
    "\n",
    "df_stemger_clean['binned'] = pd.cut(df_stemger_clean['Kiesgerechtigde bevolking'], bins, labels=labels)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "def filter_binned(df1, df2):\n",
    "    return df1[df1['CBS gemeentecode'].isin(df2['gemeentecode'])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Staffel: 1; 0-10.000 stemgerechtigden, dag: 14 maart, open op standaard dagen, stemlokalen: 28\n",
      "Staffel: 1; 0-10.000 stemgerechtigden, dag: 15 maart, open op standaard dagen, stemlokalen: 29\n",
      "Staffel: 1; 0-10.000 stemgerechtigden, dag: 16 maart, open op standaard dagen, stemlokalen: 126\n",
      "Staffel: 1; 0-10.000 stemgerechtigden, dag: 14 maart, niet open op standaard dagen, stemlokalen: 0\n",
      "Staffel: 1; 0-10.000 stemgerechtigden, dag: 15 maart, niet open op standaard dagen, stemlokalen: 4\n",
      "Staffel: 1; 0-10.000 stemgerechtigden, dag: 16 maart, niet open op standaard dagen, stemlokalen: 3\n",
      "Staffel: 2; 10.000-30.000 stemgerechtigden, dag: 14 maart, open op standaard dagen, stemlokalen: 421\n",
      "Staffel: 2; 10.000-30.000 stemgerechtigden, dag: 15 maart, open op standaard dagen, stemlokalen: 427\n",
      "Staffel: 2; 10.000-30.000 stemgerechtigden, dag: 16 maart, open op standaard dagen, stemlokalen: 2150\n",
      "Staffel: 2; 10.000-30.000 stemgerechtigden, dag: 14 maart, niet open op standaard dagen, stemlokalen: 15\n",
      "Staffel: 2; 10.000-30.000 stemgerechtigden, dag: 15 maart, niet open op standaard dagen, stemlokalen: 16\n",
      "Staffel: 2; 10.000-30.000 stemgerechtigden, dag: 16 maart, niet open op standaard dagen, stemlokalen: 101\n",
      "Staffel: 3; 30.000-60.000 stemgerechtigden, dag: 14 maart, open op standaard dagen, stemlokalen: 346\n",
      "Staffel: 3; 30.000-60.000 stemgerechtigden, dag: 15 maart, open op standaard dagen, stemlokalen: 347\n",
      "Staffel: 3; 30.000-60.000 stemgerechtigden, dag: 16 maart, open op standaard dagen, stemlokalen: 2196\n",
      "Staffel: 3; 30.000-60.000 stemgerechtigden, dag: 14 maart, niet open op standaard dagen, stemlokalen: 11\n",
      "Staffel: 3; 30.000-60.000 stemgerechtigden, dag: 15 maart, niet open op standaard dagen, stemlokalen: 16\n",
      "Staffel: 3; 30.000-60.000 stemgerechtigden, dag: 16 maart, niet open op standaard dagen, stemlokalen: 65\n",
      "Staffel: 4; 60.000-100.000 stemgerechtigden, dag: 14 maart, open op standaard dagen, stemlokalen: 177\n",
      "Staffel: 4; 60.000-100.000 stemgerechtigden, dag: 15 maart, open op standaard dagen, stemlokalen: 182\n",
      "Staffel: 4; 60.000-100.000 stemgerechtigden, dag: 16 maart, open op standaard dagen, stemlokalen: 950\n",
      "Staffel: 4; 60.000-100.000 stemgerechtigden, dag: 14 maart, niet open op standaard dagen, stemlokalen: 3\n",
      "Staffel: 4; 60.000-100.000 stemgerechtigden, dag: 15 maart, niet open op standaard dagen, stemlokalen: 1\n",
      "Staffel: 4; 60.000-100.000 stemgerechtigden, dag: 16 maart, niet open op standaard dagen, stemlokalen: 27\n",
      "Staffel: 5; 100.000-350.000 stemgerechtigden, dag: 14 maart, open op standaard dagen, stemlokalen: 197\n",
      "Staffel: 5; 100.000-350.000 stemgerechtigden, dag: 15 maart, open op standaard dagen, stemlokalen: 192\n",
      "Staffel: 5; 100.000-350.000 stemgerechtigden, dag: 16 maart, open op standaard dagen, stemlokalen: 1361\n",
      "Staffel: 5; 100.000-350.000 stemgerechtigden, dag: 14 maart, niet open op standaard dagen, stemlokalen: 13\n",
      "Staffel: 5; 100.000-350.000 stemgerechtigden, dag: 15 maart, niet open op standaard dagen, stemlokalen: 15\n",
      "Staffel: 5; 100.000-350.000 stemgerechtigden, dag: 16 maart, niet open op standaard dagen, stemlokalen: 37\n",
      "Staffel: 6; >350.000 stemgerechtigden, dag: 14 maart, open op standaard dagen, stemlokalen: 151\n",
      "Staffel: 6; >350.000 stemgerechtigden, dag: 15 maart, open op standaard dagen, stemlokalen: 151\n",
      "Staffel: 6; >350.000 stemgerechtigden, dag: 16 maart, open op standaard dagen, stemlokalen: 1010\n",
      "Staffel: 6; >350.000 stemgerechtigden, dag: 14 maart, niet open op standaard dagen, stemlokalen: 1\n",
      "Staffel: 6; >350.000 stemgerechtigden, dag: 15 maart, niet open op standaard dagen, stemlokalen: 1\n",
      "Staffel: 6; >350.000 stemgerechtigden, dag: 16 maart, niet open op standaard dagen, stemlokalen: 5\n"
     ]
    }
   ],
   "source": [
    "open_standaard = {\n",
    "        'dag': [],\n",
    "        'standaard': [],\n",
    "        'aantal': [],\n",
    "        'staffel': []\n",
    "    }\n",
    "\n",
    "def print_opening_standard(df, label, day, standard):\n",
    "    df_stemger_label = df_stemger_clean[df_stemger_clean['binned'].str.fullmatch(label)]\n",
    "    print(\"Staffel: {}, dag: {}, {}open op standaard dagen, stemlokalen: {}\".format(label, day, standard, len(filter_binned(df, df_stemger_label).index)))\n",
    "    global open_standaard\n",
    "    open_standaard['dag'].append(day)\n",
    "    open_standaard['aantal'].append(len(filter_binned(df, df_stemger_label).index))\n",
    "    open_standaard['staffel'].append(label)\n",
    "    if (standard == 'niet '):\n",
    "        open_standaard['standaard'].append(False)\n",
    "    else:\n",
    "        open_standaard['standaard'].append(True)\n",
    "for label in labels:\n",
    "    print_opening_standard(wims_standaard_14, label, \"14 maart\", \"\")\n",
    "    print_opening_standard(wims_standaard_15, label, \"15 maart\", \"\")\n",
    "    print_opening_standard(wims_standaard_16, label, \"16 maart\", \"\")\n",
    "    print_opening_standard(wims_nonstandaard_14, label, \"14 maart\", \"niet \")\n",
    "    print_opening_standard(wims_nonstandaard_15, label, \"15 maart\", \"niet \")\n",
    "    print_opening_standard(wims_nonstandaard_16, label, \"16 maart\", \"niet \")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Text(0, 0, '14 maart'), Text(1, 0, '15 maart'), Text(2, 0, '16 maart')]"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 52112 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 48560 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "df_open_standaard_full = pd.DataFrame(open_standaard)\n",
    "\n",
    "df_open_standaard_plot = df_open_standaard_full[df_open_standaard_full['standaard']].pivot(index='dag', columns=['staffel'], values=['aantal'])\n",
    "\n",
    "df_open_nonstandaard = pd.DataFrame(open_standaard)\n",
    "\n",
    "df_open_nonstandaard_plot = df_open_nonstandaard[~df_open_nonstandaard['standaard']].pivot(index='dag', columns=['staffel'], values=['aantal'])\n",
    "\n",
    "dagen_standaard = sorted(list(dict.fromkeys(open_standaard['dag'])))\n",
    "\n",
    "ax_open_standaard = df_open_standaard_plot.plot(title='Stemlokalen open op standaard tijden',kind=\"bar\", stacked=True, fontsize=22, figsize=(13,13))\n",
    "\n",
    "ax_open_nonstandaard = df_open_nonstandaard_plot.plot(title='Stemlokalen open op niet standaard tijden', kind=\"bar\", stacked=True, fontsize=22, figsize=(13,13))\n",
    "\n",
    "ax_open_standaard.set_xticklabels(dagen_standaard, fontsize=22, rotation=-45, ha=\"left\", rotation_mode=\"anchor\")\n",
    "\n",
    "ax_open_nonstandaard.set_xticklabels(dagen_standaard, fontsize=22, rotation=-45, ha=\"left\", rotation_mode=\"anchor\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Open op 14 maart groep 1; 0-10.000 stemgerechtigden: 0\n",
      "Open op 15 maart groep 1; 0-10.000 stemgerechtigden: 3\n",
      "Open op 16 maart groep 1; 0-10.000 stemgerechtigden: 95\n",
      "Open op 14 én 15 maart groep 1; 0-10.000 stemgerechtigden: 0\n",
      "Open op 14 én 16 maart groep 1; 0-10.000 stemgerechtigden: 4\n",
      "Open op 15 én 16 maart groep 1; 0-10.000 stemgerechtigden: 6\n",
      "Open op 14, 15 én 16 maart groep 1; 0-10.000 stemgerechtigden: 24\n",
      "Aantal stemlokalen open op standaard tijden 16 Maart in staffel 1; 0-10.000 stemgerechtigden: 28\n",
      "Open op 14 maart groep 2; 10.000-30.000 stemgerechtigden: 5\n",
      "Open op 15 maart groep 2; 10.000-30.000 stemgerechtigden: 4\n",
      "Open op 16 maart groep 2; 10.000-30.000 stemgerechtigden: 1804\n",
      "Open op 14 én 15 maart groep 2; 10.000-30.000 stemgerechtigden: 5\n",
      "Open op 14 én 16 maart groep 2; 10.000-30.000 stemgerechtigden: 13\n",
      "Open op 15 én 16 maart groep 2; 10.000-30.000 stemgerechtigden: 21\n",
      "Open op 14, 15 én 16 maart groep 2; 10.000-30.000 stemgerechtigden: 413\n",
      "Aantal stemlokalen open op standaard tijden 16 Maart in staffel 2; 10.000-30.000 stemgerechtigden: 421\n",
      "Open op 14 maart groep 3; 30.000-60.000 stemgerechtigden: 3\n",
      "Open op 15 maart groep 3; 30.000-60.000 stemgerechtigden: 8\n",
      "Open op 16 maart groep 3; 30.000-60.000 stemgerechtigden: 1901\n",
      "Open op 14 én 15 maart groep 3; 30.000-60.000 stemgerechtigden: 6\n",
      "Open op 14 én 16 maart groep 3; 30.000-60.000 stemgerechtigden: 11\n",
      "Open op 15 én 16 maart groep 3; 30.000-60.000 stemgerechtigden: 12\n",
      "Open op 14, 15 én 16 maart groep 3; 30.000-60.000 stemgerechtigden: 337\n",
      "Aantal stemlokalen open op standaard tijden 16 Maart in staffel 3; 30.000-60.000 stemgerechtigden: 346\n",
      "Open op 14 maart groep 4; 60.000-100.000 stemgerechtigden: 3\n",
      "Open op 15 maart groep 4; 60.000-100.000 stemgerechtigden: 1\n",
      "Open op 16 maart groep 4; 60.000-100.000 stemgerechtigden: 796\n",
      "Open op 14 én 15 maart groep 4; 60.000-100.000 stemgerechtigden: 1\n",
      "Open op 14 én 16 maart groep 4; 60.000-100.000 stemgerechtigden: 0\n",
      "Open op 15 én 16 maart groep 4; 60.000-100.000 stemgerechtigden: 5\n",
      "Open op 14, 15 én 16 maart groep 4; 60.000-100.000 stemgerechtigden: 176\n",
      "Aantal stemlokalen open op standaard tijden 16 Maart in staffel 4; 60.000-100.000 stemgerechtigden: 175\n",
      "Open op 14 maart groep 5; 100.000-350.000 stemgerechtigden: 11\n",
      "Open op 15 maart groep 5; 100.000-350.000 stemgerechtigden: 8\n",
      "Open op 16 maart groep 5; 100.000-350.000 stemgerechtigden: 1199\n",
      "Open op 14 én 15 maart groep 5; 100.000-350.000 stemgerechtigden: 0\n",
      "Open op 14 én 16 maart groep 5; 100.000-350.000 stemgerechtigden: 0\n",
      "Open op 15 én 16 maart groep 5; 100.000-350.000 stemgerechtigden: 0\n",
      "Open op 14, 15 én 16 maart groep 5; 100.000-350.000 stemgerechtigden: 199\n",
      "Aantal stemlokalen open op standaard tijden 16 Maart in staffel 5; 100.000-350.000 stemgerechtigden: 197\n",
      "Open op 14 maart groep 6; >350.000 stemgerechtigden: 0\n",
      "Open op 15 maart groep 6; >350.000 stemgerechtigden: 0\n",
      "Open op 16 maart groep 6; >350.000 stemgerechtigden: 863\n",
      "Open op 14 én 15 maart groep 6; >350.000 stemgerechtigden: 0\n",
      "Open op 14 én 16 maart groep 6; >350.000 stemgerechtigden: 0\n",
      "Open op 15 én 16 maart groep 6; >350.000 stemgerechtigden: 0\n",
      "Open op 14, 15 én 16 maart groep 6; >350.000 stemgerechtigden: 152\n",
      "Aantal stemlokalen open op standaard tijden 16 Maart in staffel 6; >350.000 stemgerechtigden: 151\n",
      "                     Openingstijden  UUID                       Staffel\n",
      "Openingstijden                                                         \n",
      "2022-03-14 07:30:00              28    28  1; 0-10.000 stemgerechtigden\n",
      "2022-03-14 08:00:00              28    28  1; 0-10.000 stemgerechtigden\n",
      "2022-03-14 08:30:00              28    28  1; 0-10.000 stemgerechtigden\n",
      "2022-03-14 09:00:00              28    28  1; 0-10.000 stemgerechtigden\n",
      "2022-03-14 09:30:00              28    28  1; 0-10.000 stemgerechtigden\n",
      "...                             ...   ...                           ...\n",
      "2022-03-16 19:00:00            1014  1014  6; >350.000 stemgerechtigden\n",
      "2022-03-16 19:30:00            1014  1014  6; >350.000 stemgerechtigden\n",
      "2022-03-16 20:00:00            1014  1014  6; >350.000 stemgerechtigden\n",
      "2022-03-16 20:30:00            1014  1014  6; >350.000 stemgerechtigden\n",
      "2022-03-16 21:00:00            1012  1012  6; >350.000 stemgerechtigden\n",
      "\n",
      "[762 rows x 3 columns]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 33996 characters]",
      "text/plain": [
       "<Figure size 1800x1800 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 35604 characters]",
      "text/plain": [
       "<Figure size 1800x1800 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 34364 characters]",
      "text/plain": [
       "<Figure size 1800x1800 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 35560 characters]",
      "text/plain": [
       "<Figure size 1800x1800 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 34784 characters]",
      "text/plain": [
       "<Figure size 1800x1800 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 33564 characters]",
      "text/plain": [
       "<Figure size 1800x1800 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "wims_datestack_grouped = pd.DataFrame()\n",
    "def make_graphs_opening(label):\n",
    "    df_stemger_label = df_stemger_clean[df_stemger_clean['binned'].str.fullmatch(label)]\n",
    "    #df_stemger_label.head()\n",
    "    graph_wims = filter_binned(gdf_wims_dedupe, df_stemger_label)\n",
    "    graph_wims_split = filter_binned(gdf_wims_split, df_stemger_label)\n",
    "    plot_opening(graph_wims_split, label)\n",
    "    \n",
    "    \n",
    "for label in labels:\n",
    "    make_graphs_opening(label)\n",
    "\n",
    "print(wims_datestack_grouped)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "wims_datestack_grouped.drop('Openingstijden', axis=1, inplace=True)\n",
    "wims_datestack_grouped.reset_index(inplace=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "def graph_open_stacked(df):\n",
    "    wims_pivot = df.pivot_table(index='Openingstijden', columns='Staffel', values='UUID', aggfunc='sum')\n",
    "\n",
    "    ax_open_opening = wims_pivot.plot(kind=\"bar\", stacked=True, fontsize=22, figsize=(40,40), log=True)\n",
    "\n",
    "\n",
    "    xticks = pd.date_range(start=df.Openingstijden.min(), end=df.Openingstijden.max(), freq=\"30min\")\n",
    "    xticklabels = []\n",
    "    tickcount = 0\n",
    "    for tick in xticks:\n",
    "        if (tickcount % 6 == 0):\n",
    "            xticklabels.append(tick.strftime(\"%d-%m %H:%M\"))\n",
    "        else:\n",
    "            xticklabels.append(\" \")\n",
    "        tickcount += 1\n",
    "\n",
    "\n",
    "    ax_open_opening.set_xticklabels(xticklabels, fontsize=22, rotation=-45, ha=\"left\", rotation_mode=\"anchor\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 88416 characters]",
      "text/plain": [
       "<Figure size 2880x2880 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "graph_open_stacked(wims_datestack_grouped)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "Invalid comparison between dtype=datetime64[ns] and Timestamp",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py:536\u001b[0m, in \u001b[0;36mDatetimeLikeArrayMixin._validate_comparison_value\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=534'>535</a>\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=535'>536</a>\u001b[0m     \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_check_compatible_with(other)\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=536'>537</a>\u001b[0m \u001b[39mexcept\u001b[39;00m (\u001b[39mTypeError\u001b[39;00m, IncompatibleFrequency) \u001b[39mas\u001b[39;00m err:\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=537'>538</a>\u001b[0m     \u001b[39m# e.g. tzawareness mismatch\u001b[39;00m\n",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py:508\u001b[0m, in \u001b[0;36mDatetimeArray._check_compatible_with\u001b[0;34m(self, other, setitem)\u001b[0m\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py?line=506'>507</a>\u001b[0m     \u001b[39mreturn\u001b[39;00m\n\u001b[0;32m--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py?line=507'>508</a>\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_assert_tzawareness_compat(other)\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py?line=508'>509</a>\u001b[0m \u001b[39mif\u001b[39;00m setitem:\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py?line=509'>510</a>\u001b[0m     \u001b[39m# Stricter check for setitem vs comparison methods\u001b[39;00m\n",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py:711\u001b[0m, in \u001b[0;36mDatetimeArray._assert_tzawareness_compat\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py?line=709'>710</a>\u001b[0m     \u001b[39mif\u001b[39;00m other_tz \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py?line=710'>711</a>\u001b[0m         \u001b[39mraise\u001b[39;00m \u001b[39mTypeError\u001b[39;00m(\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py?line=711'>712</a>\u001b[0m             \u001b[39m\"\u001b[39m\u001b[39mCannot compare tz-naive and tz-aware datetime-like objects.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py?line=712'>713</a>\u001b[0m         )\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py?line=713'>714</a>\u001b[0m \u001b[39melif\u001b[39;00m other_tz \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n",
      "\u001b[0;31mTypeError\u001b[0m: Cannot compare tz-naive and tz-aware datetime-like objects.",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[0;31mInvalidComparison\u001b[0m                         Traceback (most recent call last)",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py:1008\u001b[0m, in \u001b[0;36mDatetimeLikeArrayMixin._cmp_method\u001b[0;34m(self, other, op)\u001b[0m\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=1006'>1007</a>\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m-> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=1007'>1008</a>\u001b[0m     other \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_validate_comparison_value(other)\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=1008'>1009</a>\u001b[0m \u001b[39mexcept\u001b[39;00m InvalidComparison:\n",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py:539\u001b[0m, in \u001b[0;36mDatetimeLikeArrayMixin._validate_comparison_value\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=536'>537</a>\u001b[0m     \u001b[39mexcept\u001b[39;00m (\u001b[39mTypeError\u001b[39;00m, IncompatibleFrequency) \u001b[39mas\u001b[39;00m err:\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=537'>538</a>\u001b[0m         \u001b[39m# e.g. tzawareness mismatch\u001b[39;00m\n\u001b[0;32m--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=538'>539</a>\u001b[0m         \u001b[39mraise\u001b[39;00m InvalidComparison(other) \u001b[39mfrom\u001b[39;00m \u001b[39merr\u001b[39;00m\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=540'>541</a>\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39mnot\u001b[39;00m is_list_like(other):\n",
      "\u001b[0;31mInvalidComparison\u001b[0m: 2022-03-14 07:30:00+00:00",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb Cell 65'\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb#ch0000063?line=0'>1</a>\u001b[0m filtered_datestack_1 \u001b[39m=\u001b[39m wims_datestack_grouped\u001b[39m.\u001b[39mloc[(pd\u001b[39m.\u001b[39;49mto_datetime(wims_datestack_grouped[\u001b[39m'\u001b[39;49m\u001b[39mOpeningstijden\u001b[39;49m\u001b[39m'\u001b[39;49m]) \u001b[39m>\u001b[39;49m\u001b[39m=\u001b[39;49m pd\u001b[39m.\u001b[39;49mto_datetime(\u001b[39m'\u001b[39;49m\u001b[39m2022-03-14T07:30:00.000Z\u001b[39;49m\u001b[39m'\u001b[39;49m))\n\u001b[1;32m      <a href='vscode-notebook-cell:/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb#ch0000063?line=1'>2</a>\u001b[0m                      \u001b[39m&\u001b[39m (pd\u001b[39m.\u001b[39mto_datetime(wims_datestack_grouped[\u001b[39m'\u001b[39m\u001b[39mOpeningstijden\u001b[39m\u001b[39m'\u001b[39m]) \u001b[39m<\u001b[39m\u001b[39m=\u001b[39m pd\u001b[39m.\u001b[39mto_datetime(\u001b[39m'\u001b[39m\u001b[39m2022-03-14T21:00:00.000Z\u001b[39m\u001b[39m'\u001b[39m))]\n\u001b[1;32m      <a href='vscode-notebook-cell:/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb#ch0000063?line=2'>3</a>\u001b[0m graph_open_stacked(filtered_datestack_1)\n\u001b[1;32m      <a href='vscode-notebook-cell:/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb#ch0000063?line=3'>4</a>\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m      <a href='vscode-notebook-cell:/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb#ch0000063?line=4'>5</a>\u001b[0m \u001b[39mfiltered_datestack_2 = wims_datestack_grouped.loc[(pd.to_datetime(((wims_datestack_grouped['Openingstijden'])) >= pd.to_datetime('2022-03-15T07:30:00.000Z')))\u001b[39;00m\n\u001b[1;32m      <a href='vscode-notebook-cell:/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb#ch0000063?line=5'>6</a>\u001b[0m \u001b[39m                     & (pd.to_datetime(wims_datestack_grouped['Openingstijden']) <= pd.to_datetime('2022-03-15T21:00:00.000Z'))]\u001b[39;00m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m     <a href='vscode-notebook-cell:/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb#ch0000063?line=9'>10</a>\u001b[0m \u001b[39mgraph_open_stacked(filtered_datestack_3)\u001b[39;00m\n\u001b[1;32m     <a href='vscode-notebook-cell:/home/lillian/Code/stembureau-meting/jupyter/stembureau_data.ipynb#ch0000063?line=10'>11</a>\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/common.py:70\u001b[0m, in \u001b[0;36m_unpack_zerodim_and_defer.<locals>.new_method\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/common.py?line=65'>66</a>\u001b[0m             \u001b[39mreturn\u001b[39;00m \u001b[39mNotImplemented\u001b[39m\n\u001b[1;32m     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/common.py?line=67'>68</a>\u001b[0m other \u001b[39m=\u001b[39m item_from_zerodim(other)\n\u001b[0;32m---> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/common.py?line=69'>70</a>\u001b[0m \u001b[39mreturn\u001b[39;00m method(\u001b[39mself\u001b[39;49m, other)\n",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arraylike.py:60\u001b[0m, in \u001b[0;36mOpsMixin.__ge__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arraylike.py?line=57'>58</a>\u001b[0m \u001b[39m@unpack_zerodim_and_defer\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39m__ge__\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arraylike.py?line=58'>59</a>\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__ge__\u001b[39m(\u001b[39mself\u001b[39m, other):\n\u001b[0;32m---> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arraylike.py?line=59'>60</a>\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_cmp_method(other, operator\u001b[39m.\u001b[39;49mge)\n",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/series.py:5623\u001b[0m, in \u001b[0;36mSeries._cmp_method\u001b[0;34m(self, other, op)\u001b[0m\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/series.py?line=5619'>5620</a>\u001b[0m rvalues \u001b[39m=\u001b[39m extract_array(other, extract_numpy\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m, extract_range\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/series.py?line=5621'>5622</a>\u001b[0m \u001b[39mwith\u001b[39;00m np\u001b[39m.\u001b[39merrstate(\u001b[39mall\u001b[39m\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mignore\u001b[39m\u001b[39m\"\u001b[39m):\n\u001b[0;32m-> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/series.py?line=5622'>5623</a>\u001b[0m     res_values \u001b[39m=\u001b[39m ops\u001b[39m.\u001b[39;49mcomparison_op(lvalues, rvalues, op)\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/series.py?line=5624'>5625</a>\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_construct_result(res_values, name\u001b[39m=\u001b[39mres_name)\n",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py:269\u001b[0m, in \u001b[0;36mcomparison_op\u001b[0;34m(left, right, op)\u001b[0m\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=259'>260</a>\u001b[0m         \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=260'>261</a>\u001b[0m             \u001b[39m\"\u001b[39m\u001b[39mLengths must match to compare\u001b[39m\u001b[39m\"\u001b[39m, lvalues\u001b[39m.\u001b[39mshape, rvalues\u001b[39m.\u001b[39mshape\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=261'>262</a>\u001b[0m         )\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=263'>264</a>\u001b[0m \u001b[39mif\u001b[39;00m should_extension_dispatch(lvalues, rvalues) \u001b[39mor\u001b[39;00m (\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=264'>265</a>\u001b[0m     (\u001b[39misinstance\u001b[39m(rvalues, (Timedelta, BaseOffset, Timestamp)) \u001b[39mor\u001b[39;00m right \u001b[39mis\u001b[39;00m NaT)\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=265'>266</a>\u001b[0m     \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m is_object_dtype(lvalues\u001b[39m.\u001b[39mdtype)\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=266'>267</a>\u001b[0m ):\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=267'>268</a>\u001b[0m     \u001b[39m# Call the method on lvalues\u001b[39;00m\n\u001b[0;32m--> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=268'>269</a>\u001b[0m     res_values \u001b[39m=\u001b[39m op(lvalues, rvalues)\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=270'>271</a>\u001b[0m \u001b[39melif\u001b[39;00m is_scalar(rvalues) \u001b[39mand\u001b[39;00m isna(rvalues):  \u001b[39m# TODO: but not pd.NA?\u001b[39;00m\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=271'>272</a>\u001b[0m     \u001b[39m# numpy does not like comparisons vs None\u001b[39;00m\n\u001b[1;32m    <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/array_ops.py?line=272'>273</a>\u001b[0m     \u001b[39mif\u001b[39;00m op \u001b[39mis\u001b[39;00m operator\u001b[39m.\u001b[39mne:\n",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/common.py:70\u001b[0m, in \u001b[0;36m_unpack_zerodim_and_defer.<locals>.new_method\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/common.py?line=65'>66</a>\u001b[0m             \u001b[39mreturn\u001b[39;00m \u001b[39mNotImplemented\u001b[39m\n\u001b[1;32m     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/common.py?line=67'>68</a>\u001b[0m other \u001b[39m=\u001b[39m item_from_zerodim(other)\n\u001b[0;32m---> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/common.py?line=69'>70</a>\u001b[0m \u001b[39mreturn\u001b[39;00m method(\u001b[39mself\u001b[39;49m, other)\n",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arraylike.py:60\u001b[0m, in \u001b[0;36mOpsMixin.__ge__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arraylike.py?line=57'>58</a>\u001b[0m \u001b[39m@unpack_zerodim_and_defer\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39m__ge__\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arraylike.py?line=58'>59</a>\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__ge__\u001b[39m(\u001b[39mself\u001b[39m, other):\n\u001b[0;32m---> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arraylike.py?line=59'>60</a>\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_cmp_method(other, operator\u001b[39m.\u001b[39;49mge)\n",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py:1010\u001b[0m, in \u001b[0;36mDatetimeLikeArrayMixin._cmp_method\u001b[0;34m(self, other, op)\u001b[0m\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=1007'>1008</a>\u001b[0m     other \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_validate_comparison_value(other)\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=1008'>1009</a>\u001b[0m \u001b[39mexcept\u001b[39;00m InvalidComparison:\n\u001b[0;32m-> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=1009'>1010</a>\u001b[0m     \u001b[39mreturn\u001b[39;00m invalid_comparison(\u001b[39mself\u001b[39;49m, other, op)\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=1011'>1012</a>\u001b[0m dtype \u001b[39m=\u001b[39m \u001b[39mgetattr\u001b[39m(other, \u001b[39m\"\u001b[39m\u001b[39mdtype\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39mNone\u001b[39;00m)\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=1012'>1013</a>\u001b[0m \u001b[39mif\u001b[39;00m is_object_dtype(dtype):\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=1013'>1014</a>\u001b[0m     \u001b[39m# We have to use comp_method_OBJECT_ARRAY instead of numpy\u001b[39;00m\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=1014'>1015</a>\u001b[0m     \u001b[39m#  comparison otherwise it would fail to raise when\u001b[39;00m\n\u001b[1;32m   <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py?line=1015'>1016</a>\u001b[0m     \u001b[39m#  comparing tz-aware and tz-naive\u001b[39;00m\n",
      "File \u001b[0;32m~/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/invalid.py:34\u001b[0m, in \u001b[0;36minvalid_comparison\u001b[0;34m(left, right, op)\u001b[0m\n\u001b[1;32m     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/invalid.py?line=31'>32</a>\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/invalid.py?line=32'>33</a>\u001b[0m     typ \u001b[39m=\u001b[39m \u001b[39mtype\u001b[39m(right)\u001b[39m.\u001b[39m\u001b[39m__name__\u001b[39m\n\u001b[0;32m---> <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/invalid.py?line=33'>34</a>\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mTypeError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mInvalid comparison between dtype=\u001b[39m\u001b[39m{\u001b[39;00mleft\u001b[39m.\u001b[39mdtype\u001b[39m}\u001b[39;00m\u001b[39m and \u001b[39m\u001b[39m{\u001b[39;00mtyp\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m)\n\u001b[1;32m     <a href='file:///home/lillian/.conda/envs/stembureaus/lib/python3.10/site-packages/pandas/core/ops/invalid.py?line=34'>35</a>\u001b[0m \u001b[39mreturn\u001b[39;00m res_values\n",
      "\u001b[0;31mTypeError\u001b[0m: Invalid comparison between dtype=datetime64[ns] and Timestamp"
     ]
    }
   ],
   "source": [
    "filtered_datestack_1 = wims_datestack_grouped.loc[(pd.to_datetime(wims_datestack_grouped['Openingstijden']) >= pd.to_datetime('2022-03-14T07:30:00.000Z'))\n",
    "                     & (pd.to_datetime(wims_datestack_grouped['Openingstijden']) <= pd.to_datetime('2022-03-14T21:00:00.000Z'))]\n",
    "graph_open_stacked(filtered_datestack_1)\n",
    "\"\"\"\n",
    "filtered_datestack_2 = wims_datestack_grouped.loc[(pd.to_datetime(((wims_datestack_grouped['Openingstijden'])) >= pd.to_datetime('2022-03-15T07:30:00.000Z')))\n",
    "                     & (pd.to_datetime(wims_datestack_grouped['Openingstijden']) <= pd.to_datetime('2022-03-15T21:00:00.000Z'))]\n",
    "graph_open_stacked(filtered_datestack_2)\n",
    "filtered_datestack_3 = wims_datestack_grouped.loc[(pd.to_datetime(wims_datestack_grouped['Openingstijden']) >= pd.to_datetime('2022-03-16T07:30:00.000Z'))\n",
    "                     & (pd.to_datetime(wims_datestack_grouped['Openingstijden']) <= pd.to_datetime('2022-03-16T21:00:00.000Z'))]\n",
    "graph_open_stacked(filtered_datestack_3)\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Staffel: 1; 0-10.000 stemgerechtigden\n",
      "bijeenkomstfunctie         82\n",
      "kantoorfunctie             23\n",
      "sportfunctie               22\n",
      "woonfunctie                15\n",
      "overige gebruiksfunctie    12\n",
      "onderwijsfunctie           10\n",
      "gezondheidszorgfunctie      6\n",
      "winkelfunctie               3\n",
      "industriefunctie            1\n",
      "Name: Gebruiksdoel van het gebouw, dtype: int64\n",
      "Staffel: 2; 10.000-30.000 stemgerechtigden\n",
      "bijeenkomstfunctie         1369\n",
      "sportfunctie                415\n",
      "kantoorfunctie              259\n",
      "onderwijsfunctie            243\n",
      "woonfunctie                 211\n",
      "overige gebruiksfunctie      89\n",
      "gezondheidszorgfunctie       78\n",
      "industriefunctie             38\n",
      "winkelfunctie                36\n",
      "logiesfunctie                33\n",
      "Name: Gebruiksdoel van het gebouw, dtype: int64\n",
      "Staffel: 3; 30.000-60.000 stemgerechtigden\n",
      "bijeenkomstfunctie         1414\n",
      "sportfunctie                384\n",
      "onderwijsfunctie            268\n",
      "kantoorfunctie              203\n",
      "woonfunctie                 181\n",
      "overige gebruiksfunctie     108\n",
      "gezondheidszorgfunctie      100\n",
      "industriefunctie             51\n",
      "winkelfunctie                34\n",
      "logiesfunctie                26\n",
      "celfunctie                    1\n",
      "Name: Gebruiksdoel van het gebouw, dtype: int64\n",
      "Staffel: 4; 60.000-100.000 stemgerechtigden\n",
      "bijeenkomstfunctie         531\n",
      "sportfunctie               161\n",
      "onderwijsfunctie           141\n",
      "woonfunctie                 82\n",
      "kantoorfunctie              80\n",
      "gezondheidszorgfunctie      43\n",
      "overige gebruiksfunctie     39\n",
      "industriefunctie            21\n",
      "winkelfunctie               19\n",
      "logiesfunctie                7\n",
      "celfunctie                   1\n",
      "Name: Gebruiksdoel van het gebouw, dtype: int64\n",
      "Staffel: 5; 100.000-350.000 stemgerechtigden\n",
      "bijeenkomstfunctie         667\n",
      "onderwijsfunctie           298\n",
      "sportfunctie               239\n",
      "kantoorfunctie             138\n",
      "woonfunctie                115\n",
      "overige gebruiksfunctie     60\n",
      "gezondheidszorgfunctie      55\n",
      "industriefunctie            41\n",
      "winkelfunctie               29\n",
      "logiesfunctie               12\n",
      "celfunctie                   1\n",
      "Name: Gebruiksdoel van het gebouw, dtype: int64\n",
      "Staffel: 6; >350.000 stemgerechtigden\n",
      "bijeenkomstfunctie         403\n",
      "onderwijsfunctie           228\n",
      "sportfunctie               114\n",
      "kantoorfunctie              91\n",
      "woonfunctie                 80\n",
      "industriefunctie            52\n",
      "overige gebruiksfunctie     38\n",
      "winkelfunctie               28\n",
      "gezondheidszorgfunctie      27\n",
      "logiesfunctie               26\n",
      "Name: Gebruiksdoel van het gebouw, dtype: int64\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 30988 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 33012 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 33552 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 32416 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 32976 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 32928 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "def make_graphs_use(label):\n",
    "    df_stemger_label = df_stemger_clean[df_stemger_clean['binned'].str.fullmatch(label)]\n",
    "    plot_use(filter_binned(gdf_wims_dedupe, df_stemger_label), label)\n",
    "\n",
    "for label in labels:\n",
    "    make_graphs_use(label)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Open op 14 maart groep totaal: 22\n",
      "Open op 15 maart groep totaal: 24\n",
      "Open op 16 maart groep totaal: 6658\n",
      "Open op 14 én 15 maart groep totaal: 12\n",
      "Open op 14 én 16 maart groep totaal: 28\n",
      "Open op 15 én 16 maart groep totaal: 44\n",
      "Open op 14, 15 én 16 maart groep totaal: 1301\n",
      "Aantal stemlokalen open op standaard tijden 16 Maart in staffel totaal: 1318\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 34076 characters]",
      "text/plain": [
       "<Figure size 1800x1800 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_opening(gdf_wims_split, \"totaal\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Staffel: totaal\n",
      "bijeenkomstfunctie         4466\n",
      "sportfunctie               1335\n",
      "onderwijsfunctie           1188\n",
      "kantoorfunctie              794\n",
      "woonfunctie                 684\n",
      "overige gebruiksfunctie     346\n",
      "gezondheidszorgfunctie      309\n",
      "industriefunctie            204\n",
      "winkelfunctie               149\n",
      "logiesfunctie               104\n",
      "celfunctie                    3\n",
      "Name: Gebruiksdoel van het gebouw, dtype: int64\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 30436 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_use(gdf_wims_dedupe, \"totaal\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2; 10.000-30.000 stemgerechtigden      170\n",
      "3; 30.000-60.000 stemgerechtigden       92\n",
      "1; 0-10.000 stemgerechtigden            25\n",
      "4; 60.000-100.000 stemgerechtigden      24\n",
      "5; 100.000-350.000 stemgerechtigden     19\n",
      "6; >350.000 stemgerechtigden             3\n",
      "Name: binned, dtype: int64\n"
     ]
    }
   ],
   "source": [
    " print(df_stemger_clean['binned'].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 25740 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 61848 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 26332 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 78012 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 26844 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 78508 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 25684 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 74928 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 27024 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 76520 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 26420 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 66572 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "def make_graphs_dist(label):\n",
    "    df_stemger_label = df_stemger_clean[df_stemger_clean['binned'].str.fullmatch(label)]\n",
    "    plot_dist(filter_binned(df_nearest, df_stemger_label), label)\n",
    "\n",
    "for label in labels:\n",
    "    make_graphs_dist(label)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gemiddelde afstand tot stemlokaal totaal: 434.3908324541042\n",
      "['crs28992res500m', 'aantal_inwoners', 'stedelijkheid', 'geometry', 'savedindex', 'Unnamed: 0', '_id', 'Gemeente', 'gemeentecode', 'Nummer stembureau', 'Naam stembureau', 'Gebruiksdoel van het gebouw', 'Website locatie', 'Wijknaam', 'CBS wijknummer', 'Buurtnaam', 'CBS buurtnummer', 'BAG Nummeraanduiding ID', 'Straatnaam', 'Huisnummer', 'Huisletter', 'Huisnummertoevoeging', 'Postcode', 'Plaats', 'Extra adresaanduiding', 'X', 'Y', 'Latitude', 'Longitude', 'Openingstijden 14-03-2022', 'Openingstijden 15-03-2022', 'Openingstijden 16-03-2022', 'Toegankelijk voor mensen met een lichamelijke beperking', 'Akoestiek', 'Auditieve hulpmiddelen', 'Visuele hulpmiddelen', 'Gehandicaptentoilet', 'Kieskring ID', 'Hoofdstembureau', 'Tellocatie', 'Contactgegevens gemeente', 'Verkiezingswebsite gemeente', 'Verkiezingen', 'ID', 'UUID', 'dist']\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "binned\n",
       "1; 0-10.000 stemgerechtigden           582.737580\n",
       "2; 10.000-30.000 stemgerechtigden      539.170370\n",
       "3; 30.000-60.000 stemgerechtigden      472.161641\n",
       "4; 60.000-100.000 stemgerechtigden     451.049861\n",
       "5; 100.000-350.000 stemgerechtigden    357.505034\n",
       "6; >350.000 stemgerechtigden           231.455703\n",
       "dtype: float64"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def w_avg(df, values, weights):\n",
    "    d = df[values]\n",
    "    w = df[weights]\n",
    "    return (d * w).sum() / w.sum()\n",
    "print(\"Gemiddelde afstand tot stemlokaal totaal: {}\".format(w_avg(df_nearest, \"dist\", \"aantal_inwoners\")))\n",
    "\n",
    "df_nearest_rename = df_nearest.rename(columns = {'CBS gemeentecode': 'gemeentecode'})\n",
    "print(list(df_nearest_rename))\n",
    "df_nearest_merged = pd.merge(df_nearest_rename, df_stemger_clean, on=['gemeentecode'])\n",
    "df_nearest_merged.groupby('binned').apply(w_avg, 'dist', 'aantal_inwoners')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "324.59925001723775\n",
      "binned\n",
      "1; 0-10.000 stemgerechtigden           420.523944\n",
      "2; 10.000-30.000 stemgerechtigden      387.837924\n",
      "3; 30.000-60.000 stemgerechtigden      357.802769\n",
      "4; 60.000-100.000 stemgerechtigden     338.623546\n",
      "5; 100.000-350.000 stemgerechtigden    298.937122\n",
      "6; >350.000 stemgerechtigden           213.189891\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "def weighted_median(df, val, weight):\n",
    "    df_sorted = df.sort_values(val)\n",
    "    cumsum = df_sorted[weight].cumsum()\n",
    "    cutoff = df_sorted[weight].sum() / 2.\n",
    "    return df_sorted[cumsum >= cutoff][val].iloc[0]\n",
    "\n",
    "print(weighted_median(df_nearest_merged, 'dist', 'aantal_inwoners'))\n",
    "\n",
    "print(df_nearest_merged.groupby('binned').apply(weighted_median, 'dist', 'aantal_inwoners'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_nearest_merged['New']=df_nearest_merged[['aantal_inwoners','r2']].apply(tuple ,1);df_nearest_merged.groupby(['binned']).New.value_counts().reindex(pd.MultiIndex.from_frame(df_nearest_merged[['binned','New']])).values\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 24316 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 936x936 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 69556 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_dist(df_nearest, \"totaal\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "def print_type(df, label):\n",
    "    print(\"aantal mobiele stemlokalen groep {}: {}\".format(label, df[df[\"Naam stembureau\"].str.contains(\"Mobiel\")][\"Naam stembureau\"].count()))\n",
    "    print(\"aantal drive through stemlokalen groep {}: {}\".format(label, df[df[\"Naam stembureau\"].str.contains(\"Drive\")][\"Naam stembureau\"].count()))\n",
    "    df_publiek = df.dropna(subset=['Extra adresaanduiding'])\n",
    "    print(\"aantal niet publiek open stemlokalen groep {}: {}\".format(label, df_publiek[df_publiek[\"Extra adresaanduiding\"].str.contains(\"Niet open voor algemeen publiek\")][\"Extra adresaanduiding\"].count()))\n",
    "    print(\"aantal tent stemlokalen groep {}: {}\".format(label, df[df[\"Naam stembureau\"].str.contains(\"tent\")][\"Naam stembureau\"].count()))\n",
    "    print(\"aantal parkeerplaats stemlokalen groep {}: {}\".format(label, df[df[\"Naam stembureau\"].str.contains(\"parkeer\")][\"Naam stembureau\"].count()))\n",
    "    print(\"aantal bus stemlokalen groep {}: {}\".format(label, df[df[\"Naam stembureau\"].str.contains(\"bus\")][\"Naam stembureau\"].count()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aantal mobiele stemlokalen groep totaal: 98\n",
      "aantal drive through stemlokalen groep totaal: 25\n",
      "aantal niet publiek open stemlokalen groep totaal: 89\n",
      "aantal tent stemlokalen groep totaal: 13\n",
      "aantal parkeerplaats stemlokalen groep totaal: 13\n",
      "aantal bus stemlokalen groep totaal: 23\n",
      "\n",
      "\n",
      "aantal mobiele stemlokalen groep 1; 0-10.000 stemgerechtigden: 3\n",
      "aantal drive through stemlokalen groep 1; 0-10.000 stemgerechtigden: 1\n",
      "aantal niet publiek open stemlokalen groep 1; 0-10.000 stemgerechtigden: 3\n",
      "aantal tent stemlokalen groep 1; 0-10.000 stemgerechtigden: 0\n",
      "aantal parkeerplaats stemlokalen groep 1; 0-10.000 stemgerechtigden: 0\n",
      "aantal bus stemlokalen groep 1; 0-10.000 stemgerechtigden: 0\n",
      "\n",
      "\n",
      "aantal mobiele stemlokalen groep 2; 10.000-30.000 stemgerechtigden: 30\n",
      "aantal drive through stemlokalen groep 2; 10.000-30.000 stemgerechtigden: 5\n",
      "aantal niet publiek open stemlokalen groep 2; 10.000-30.000 stemgerechtigden: 27\n",
      "aantal tent stemlokalen groep 2; 10.000-30.000 stemgerechtigden: 3\n",
      "aantal parkeerplaats stemlokalen groep 2; 10.000-30.000 stemgerechtigden: 8\n",
      "aantal bus stemlokalen groep 2; 10.000-30.000 stemgerechtigden: 5\n",
      "\n",
      "\n",
      "aantal mobiele stemlokalen groep 3; 30.000-60.000 stemgerechtigden: 39\n",
      "aantal drive through stemlokalen groep 3; 30.000-60.000 stemgerechtigden: 7\n",
      "aantal niet publiek open stemlokalen groep 3; 30.000-60.000 stemgerechtigden: 25\n",
      "aantal tent stemlokalen groep 3; 30.000-60.000 stemgerechtigden: 0\n",
      "aantal parkeerplaats stemlokalen groep 3; 30.000-60.000 stemgerechtigden: 1\n",
      "aantal bus stemlokalen groep 3; 30.000-60.000 stemgerechtigden: 9\n",
      "\n",
      "\n",
      "aantal mobiele stemlokalen groep 4; 60.000-100.000 stemgerechtigden: 10\n",
      "aantal drive through stemlokalen groep 4; 60.000-100.000 stemgerechtigden: 7\n",
      "aantal niet publiek open stemlokalen groep 4; 60.000-100.000 stemgerechtigden: 11\n",
      "aantal tent stemlokalen groep 4; 60.000-100.000 stemgerechtigden: 5\n",
      "aantal parkeerplaats stemlokalen groep 4; 60.000-100.000 stemgerechtigden: 0\n",
      "aantal bus stemlokalen groep 4; 60.000-100.000 stemgerechtigden: 0\n",
      "\n",
      "\n",
      "aantal mobiele stemlokalen groep 5; 100.000-350.000 stemgerechtigden: 16\n",
      "aantal drive through stemlokalen groep 5; 100.000-350.000 stemgerechtigden: 5\n",
      "aantal niet publiek open stemlokalen groep 5; 100.000-350.000 stemgerechtigden: 23\n",
      "aantal tent stemlokalen groep 5; 100.000-350.000 stemgerechtigden: 3\n",
      "aantal parkeerplaats stemlokalen groep 5; 100.000-350.000 stemgerechtigden: 4\n",
      "aantal bus stemlokalen groep 5; 100.000-350.000 stemgerechtigden: 9\n",
      "\n",
      "\n",
      "aantal mobiele stemlokalen groep 6; >350.000 stemgerechtigden: 0\n",
      "aantal drive through stemlokalen groep 6; >350.000 stemgerechtigden: 0\n",
      "aantal niet publiek open stemlokalen groep 6; >350.000 stemgerechtigden: 0\n",
      "aantal tent stemlokalen groep 6; >350.000 stemgerechtigden: 2\n",
      "aantal parkeerplaats stemlokalen groep 6; >350.000 stemgerechtigden: 0\n",
      "aantal bus stemlokalen groep 6; >350.000 stemgerechtigden: 0\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print_type(gdf_wims_dedupe, \"totaal\")\n",
    "print(\"\\n\")\n",
    "\n",
    "def make_print_type(label):\n",
    "    df_stemger_label = df_stemger_clean[df_stemger_clean['binned'].str.fullmatch(label)]\n",
    "    print_type(filter_binned(gdf_wims_dedupe, df_stemger_label), label)\n",
    "\n",
    "for label in labels: \n",
    "    make_print_type(label)\n",
    "    print(\"\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "#print(list(gdf_wims_dedupe))\n",
    "\n",
    "#print(list(df_stemger_clean))\n",
    "\n",
    "\n",
    "#gdf_wims_dedupe.rename(columns = {'CBS gemeentecode': 'gemeentecode'}, inplace = True)\n",
    "#wims_merged = pd.merge(gdf_wims_dedupe, df_stemger_clean, on=['gemeentecode'])\n",
    "#wims_merged.rename(columns = {'binned': 'staffel'}, inplace = True)\n",
    "#wims_merged.to_csv(path_or_buf='../data/export/openingstijden_alle_staffels.csv', sep=';', na_rep='', header=True, date_format = '%m-%d %H:%M')\n",
    "\n",
    "#df_nearest.rename(columns = {'CBS gemeentecode': 'gemeentecode'}, inplace = True)\n",
    "#df_merged = pd.merge(df_nearest, df_stemger_clean, on=['gemeentecode'])\n",
    "#df_merged.rename(columns = {'binned': 'staffel'}, inplace = True)\n",
    "#df_merged.to_csv(path_or_buf='../data/export/afstand_alle_staffels.csv', sep=';', na_rep='', header=True, date_format = '%m-%d %H:%M')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "#de eerste vijf rijen zijn meta-data en kunnen we gerust weghalen voor nu \n",
    "#df_gr_gr = pd.read_csv(r'../data/stemmen/01_Groningen/#osv4-3_telling_gr2022_groningen.csv', skiprows=5, header=None, delimiter=';')\n",
    "#print(df_gr_gr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 75752 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "open = {\n",
    "        'dagen': [],\n",
    "        'aantal': [],\n",
    "        'staffel': []\n",
    "    }\n",
    "\n",
    "\n",
    "def graph_open_2(df, label):\n",
    "    \n",
    "    open['dagen'].append(\"14 en 15 maart\")\n",
    "    open['aantal'].append(df[df['Openingstijden 16-03-2022 van'].isnull()].dropna(subset=['Openingstijden 15-03-2022 van'])['Openingstijden 14-03-2022 van'].count())\n",
    "    open['staffel'].append(label)\n",
    "\n",
    "    open['dagen'].append(\"14 en 16 maart\")\n",
    "    open['aantal'].append(df[df['Openingstijden 15-03-2022 van'].isnull()].dropna(subset=['Openingstijden 16-03-2022 van'])['Openingstijden 14-03-2022 van'].count())\n",
    "    open['staffel'].append(label)\n",
    "\n",
    "    open['dagen'].append(\"15 en 16 maart\")\n",
    "    open['aantal'].append(df[df['Openingstijden 14-03-2022 van'].isnull()].dropna(subset=['Openingstijden 15-03-2022 van'])['Openingstijden 16-03-2022 van'].count())\n",
    "    open['staffel'].append(label)\n",
    "\n",
    "    open['dagen'].append(\"Alle dagen\")\n",
    "    open['aantal'].append(df.dropna(subset=['Openingstijden 16-03-2022 van', 'Openingstijden 15-03-2022 van'])['Openingstijden 14-03-2022 van'].count())\n",
    "    open['staffel'].append(label)\n",
    "\n",
    "    open['dagen'].append(\"Alleen 14 maart\")\n",
    "    open['aantal'].append(df[df['Openingstijden 15-03-2022 van'].isnull()][df['Openingstijden 16-03-2022 van'].isnull()]['Openingstijden 14-03-2022 van'].count())\n",
    "    open['staffel'].append(label)\n",
    "\n",
    "    open['dagen'].append(\"Alleen 15 maart\")\n",
    "    open['aantal'].append(df[df['Openingstijden 14-03-2022 van'].isnull()][df['Openingstijden 16-03-2022 van'].isnull()]['Openingstijden 15-03-2022 van'].count())\n",
    "    open['staffel'].append(label)\n",
    "\n",
    "    open['dagen'].append(\"Alleen 16 maart\")\n",
    "    open['aantal'].append(df[df['Openingstijden 14-03-2022 van'].isnull()][df['Openingstijden 15-03-2022 van'].isnull()]['Openingstijden 16-03-2022 van'].count())\n",
    "    open['staffel'].append(label)\n",
    "\n",
    "\n",
    "def make_graph_open_2(label):\n",
    "    df_stemger_label = df_stemger_clean[df_stemger_clean['binned'].str.fullmatch(label)]\n",
    "    graph_open_2(filter_binned(gdf_wims_times, df_stemger_label), label)\n",
    "\n",
    "for label in labels: \n",
    "    make_graph_open_2(label)\n",
    "\n",
    "dagen = sorted(list(dict.fromkeys(open['dagen'])))\n",
    "\n",
    "df_open_dagen = pd.DataFrame(open).pivot(index='dagen', columns=['staffel'], values=['aantal'])\n",
    "\n",
    "#ax_open = pd.DataFrame(open).pivot(index='dagen', columns=['staffel'], values=['aantal']).plot(kind=\"bar\", stacked=True, figsize=(13,13), fontsize=22)\n",
    "\n",
    "#ax_open.set_xticklabels(dagen, fontsize=22, rotation=-45, ha=\"left\", rotation_mode=\"anchor\")\n",
    "\n",
    "#for c in ax_open.containers:\n",
    "\n",
    "    # Optional: if the segment is small or 0, customize the labels\n",
    "    #labels_ax= [v.get_height() if v.get_height() > 0 else '' for v in c]\n",
    "    \n",
    "    # remove the labels parameter if it's not needed for customized labels\n",
    "    #ax_open.bar_label(c, labels=labels_ax, label_type='center')\n",
    "\n",
    "ax_open_log = pd.DataFrame(open).pivot(index='dagen', columns=['staffel'], values=['aantal']).plot(kind=\"bar\", stacked=True, fontsize=22, figsize=(13,13), log=True)\n",
    "\n",
    "ax_open_log.set_xticklabels(dagen, fontsize=22, rotation=-45, ha=\"left\", rotation_mode=\"anchor\")\n",
    "\n",
    "for c in ax_open_log.containers:\n",
    "\n",
    "    # Optional: if the segment is small or 0, customize the labels\n",
    "    labels_ax = [v.get_height() for v in c]\n",
    "    \n",
    "    # remove the labels parameter if it's not needed for customized labels\n",
    "    ax_open_log.bar_label(c, labels=labels_ax, label_type='center', padding = 0)\n",
    "\n",
    "#pd.DataFrame(open).pivot(index='dagen', columns=['staffel'], values=['aantal']).plot(kind=\"bar\", stacked=True, figsize=(13,13))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 51220 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "amount = {\n",
    "        ' ': [],\n",
    "        'aantal': [],\n",
    "        'staffel': []\n",
    "    }\n",
    "\n",
    "def graph_count(df, label):\n",
    "    amount[' '].append(\"Stemlokaal\")\n",
    "    amount['aantal'].append(df[\"UUID\"].count())\n",
    "    amount['staffel'].append(label)\n",
    "\n",
    "def make_graph_count(label):\n",
    "    df_stemger_label = df_stemger_clean[df_stemger_clean['binned'].str.fullmatch(label)]\n",
    "    graph_count(filter_binned(gdf_wims_dedupe, df_stemger_label), label)\n",
    "\n",
    "for label in labels: \n",
    "    make_graph_count(label)\n",
    "\n",
    "\n",
    "\n",
    "ax_stemlok = pd.DataFrame(amount).pivot(index=' ', columns=['staffel'], values=['aantal']).plot(kind=\"bar\", stacked=True, figsize=(13,13), fontsize=22)\n",
    "\n",
    "ax_stemlok.set_xticklabels(['Stemlokalen'], fontsize=22, rotation=0, ha=\"center\", rotation_mode=\"anchor\")\n",
    "\n",
    "for c in ax_stemlok.containers:\n",
    "\n",
    "    # Optional: if the segment is small or 0, customize the labels\n",
    "    labels_ax = [v.get_height() if v.get_height() > 0 else '' for v in c]\n",
    "    \n",
    "    # remove the labels parameter if it's not needed for customized labels\n",
    "    ax_stemlok.bar_label(c, labels=labels_ax, label_type='center')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 103216 characters]",
      "text/plain": [
       "<Figure size 936x936 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "counts =   {'type': [],\n",
    "                'aantal': [],\n",
    "                'staffel': []}\n",
    "def graph_type(df, label):\n",
    "    \n",
    "    counts['type'].append(\"Mobiel stemlokaal\") \n",
    "    counts['aantal'].append(df[df[\"Naam stembureau\"].str.contains(\"Mobiel\")][\"Naam stembureau\"].count())\n",
    "    counts['staffel'].append(label)\n",
    "    counts['type'].append(\"Drive-through stemlokaal\")\n",
    "    counts['aantal'].append(df[df[\"Naam stembureau\"].str.contains(\"Drive\")][\"Naam stembureau\"].count())\n",
    "    counts['staffel'].append(label)\n",
    "    df_publiek = df.dropna(subset=['Extra adresaanduiding'])\n",
    "    counts['type'].append(\"Niet open algemeen publiek\")\n",
    "    counts['aantal'].append(df_publiek[df_publiek[\"Extra adresaanduiding\"].str.contains(\"Niet open voor algemeen publiek\")][\"Extra adresaanduiding\"].count())\n",
    "    counts['staffel'].append(label)\n",
    "    counts['type'].append(\"Tent stemlokaal\")\n",
    "    counts['aantal'].append(df[df[\"Naam stembureau\"].str.contains(\"tent\")][\"Naam stembureau\"].count())\n",
    "    counts['staffel'].append(label)\n",
    "    counts['type'].append(\"Parkeerplaats stemlokaal\")\n",
    "    counts['aantal'].append(df[df[\"Naam stembureau\"].str.contains(\"parkeer\")][\"Naam stembureau\"].count())\n",
    "    counts['staffel'].append(label)\n",
    "    counts['type'].append(\"Bus stemlokaal\")\n",
    "    counts['aantal'].append(df[df[\"Naam stembureau\"].str.contains(\"bus\")][\"Naam stembureau\"].count())\n",
    "    counts['staffel'].append(label)\n",
    "\n",
    "def make_graph_type_2(label):\n",
    "    df_stemger_label = df_stemger_clean[df_stemger_clean['binned'].str.fullmatch(label)]\n",
    "    graph_type(filter_binned(gdf_wims_dedupe, df_stemger_label), label)\n",
    "\n",
    "for label in labels: \n",
    "    make_graph_type_2(label)\n",
    "\n",
    "types = ['Bus stemlokaal', 'Drive through stemlokaal', 'Mobiel stemlokaal', 'Niet open voor algemeen publiek', 'Parkeerplaats stemlokaal', 'Tent stemlokaal']\n",
    "\n",
    "ax = pd.DataFrame(counts).pivot(index='type', columns=['staffel'], values=['aantal']).plot(kind=\"bar\", stacked=True, figsize=(13,13), fontsize=22)\n",
    "\n",
    "ax.set_xticklabels(types, fontsize=22, rotation=-45, ha=\"left\", rotation_mode=\"anchor\")\n",
    "\n",
    "for c in ax.containers:\n",
    "\n",
    "    # Optional: if the segment is small or 0, customize the labels\n",
    "    labels_ax = [v.get_height() if v.get_height() > 0 else '' for v in c]\n",
    "    \n",
    "    # remove the labels parameter if it's not needed for customized labels\n",
    "    ax.bar_label(c, labels=labels_ax, label_type='center')\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "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. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "#TODO:mobiele stemlokalen eruit filteren die NIET 0,0 zijn\n",
    "#TODO:datastandaard duitse verkiezingen stemlokaalafstand opzoeken"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  },
  "vscode": {
   "interpreter": {
    "hash": "3f7157711c67e7ebfc0cc7689d725ee0494e8877e666bd284df94ccbb1347e28"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
