%22%22%22Tutorial%206%3A%20read%20four%20Berlin%20elections%20with%20one%20set%20of%20reader%20options%3B%20the%20next%20election%20is%20one%20more%20URL.%0A%0ARun%20with%3A%20uv%20run%20marimo%20edit%20tutorials%2F06_a_new_election.py%20(needs%20network%20access%2C%20no%20account).%0A%22%22%22%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%20Tutorial%206%3A%20a%20new%20election%0A%0A%20%20%20%20**Goal%3A**%20read%20four%20Berlin%20elections%20with%20one%20set%20of%20reader%20options%2C%20and%20see%20that%20the%20next%20election%0A%20%20%20%20takes%20one%20more%20URL.%0A%0A%20%20%20%20**Time%3A**%20about%2015%20minutes.%20**You%20need%3A**%20basic%20Python%20and%20a%20network%20connection.%20No%20account.%0A%0A%20%20%20%20**Setup%3A**%20clone%20the%20repository%20and%20run%20%60uv%20sync%20--all-extras%60%20(see%20the%20README)%2C%20then%0A%20%20%20%20%60uv%20run%20marimo%20edit%20tutorials%2F06_a_new_election.py%60.%0A%0A%20%20%20%20In%20%5Btutorial%202%5D(https%3A%2F%2Fgithub.com%2Fmloda-ai%2Fmloda-plugin-govdata%2Fblob%2Fmain%2Ftutorials%2F02_elections_and_air_quality.py)%0A%20%20%20%20you%20told%20the%20election%20reader%20how%20the%20federal%20results%20file%20is%20laid%20out.%20Berlin%20publishes%20its%20own%0A%20%20%20%20results%20files%2C%20laid%20out%20differently.%20But%20every%20Berlin%20election%20uses%20the%20same%20layout%2C%20so%20you%20describe%0A%20%20%20%20it%20once.%0A%0A%20%20%20%20Berlin%20is%20a%20city%20and%20one%20of%20Germany's%2016%20federal%20states%20(*L%C3%A4nder*).%20Its%20state%20parliament%20is%20the%0A%20%20%20%20*Abgeordnetenhaus*%20(AGH).%20The%20state%20returning%20officer%20(*Landeswahlleiter*)%20runs%20the%20elections%20in%0A%20%20%20%20Berlin%20and%20publishes%20the%20results%20for%20each%20voting%20district%20in%20the%20city's%2012%20boroughs%20(*Bezirke*).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20altair%20as%20alt%0A%20%20%20%20import%20pandas%20as%20pd%0A%0A%20%20%20%20from%20mloda.user%20import%20Feature%2C%20mloda%0A%20%20%20%20from%20mloda_plugin_govdata.feature_groups.govdata%20import%20(%0A%20%20%20%20%20%20%20%20OPTION_WAHL_HEADER_ROWS%2C%0A%20%20%20%20%20%20%20%20OPTION_WAHL_LABEL_COLUMNS%2C%0A%20%20%20%20%20%20%20%20OPTION_WAHL_SKIPROWS%2C%0A%20%20%20%20%20%20%20%20OPTION_WAHL_VALUE_TYPE%2C%0A%20%20%20%20%20%20%20%20BundeswahlleiterinReader%2C%0A%20%20%20%20%20%20%20%20ColumnType%2C%0A%20%20%20%20%20%20%20%20DownloadCache%2C%0A%20%20%20%20%20%20%20%20build_client%2C%0A%20%20%20%20)%0A%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20BundeswahlleiterinReader%2C%0A%20%20%20%20%20%20%20%20ColumnType%2C%0A%20%20%20%20%20%20%20%20DownloadCache%2C%0A%20%20%20%20%20%20%20%20Feature%2C%0A%20%20%20%20%20%20%20%20OPTION_WAHL_HEADER_ROWS%2C%0A%20%20%20%20%20%20%20%20OPTION_WAHL_LABEL_COLUMNS%2C%0A%20%20%20%20%20%20%20%20OPTION_WAHL_SKIPROWS%2C%0A%20%20%20%20%20%20%20%20OPTION_WAHL_VALUE_TYPE%2C%0A%20%20%20%20%20%20%20%20alt%2C%0A%20%20%20%20%20%20%20%20build_client%2C%0A%20%20%20%20%20%20%20%20mloda%2C%0A%20%20%20%20%20%20%20%20pd%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%20Step%201%3A%20look%20at%20the%20file%0A%0A%20%20%20%20Start%20with%20the%20Abgeordnetenhaus%20election%20of%2012%20February%202023.%20It%20repeated%20the%202021%20election%2C%20which%20a%0A%20%20%20%20court%20had%20declared%20invalid.%20Each%20voter%20has%20two%20votes%3A%20the%20first%20for%20a%20local%20candidate%2C%20the%20second%0A%20%20%20%20(*Zweitstimme*)%20for%20a%20party.%20The%20file%20holds%20the%20second%20votes.%20This%20cell%20downloads%20it%2C%20keeps%20a%20copy%20on%0A%20%20%20%20your%20disk%20and%20shows%20the%20first%20three%20lines%2C%20each%20cut%20to%20150%20characters.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20AGH_2023_URL%20%3D%20%22https%3A%2F%2Fwww.wahlen-berlin.de%2Fwahlen%2FBE2023%2FAFSPRAES%2Fagh%2FDatenexport_AGH2023_Zweitstimme_W_BE.csv%22%0A%20%20%20%20return%20(AGH_2023_URL%2C)%0A%0A%0A%40app.cell%0Adef%20_(AGH_2023_URL%2C%20BundeswahlleiterinReader%2C%20DownloadCache%2C%20build_client%2C%20mo)%3A%0A%20%20%20%20with%20build_client()%20as%20_client%2C%20DownloadCache(BundeswahlleiterinReader.cache_dir%2C%20client%3D_client)%20as%20_cache%3A%0A%20%20%20%20%20%20%20%20_path%20%3D%20_cache.get_or_download(AGH_2023_URL).path%0A%20%20%20%20_lines%20%3D%20_path.read_text(encoding%3D%22utf-8-sig%22).splitlines()%0A%20%20%20%20mo.plain_text(%22%5Cn%22.join(_line%5B%3A150%5D%20for%20_line%20in%20_lines%5B%3A3%5D))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20The%20first%20line%20is%20the%20header%2C%20with%20nothing%20before%20it.%20Then%20comes%20one%20row%20per%20voting%20district.%0A%0A%20%20%20%20-%20The%20first%2012%20columns%20are%20text.%20%60Bezirksname%60%20is%20the%20borough's%20name.%20%60WBezArt%60%20is%20the%20kind%20of%0A%20%20%20%20%20%20district%3A%20%60W%60%20for%20a%20polling%20station%2C%20%60B%60%20for%20postal%20votes%20(*Briefwahl*).%0A%20%20%20%20-%20The%20rest%20are%20numbers.%20%60WberIns%60%20counts%20the%20eligible%20voters%20(*Wahlberechtigte%20insgesamt*)%2C%20%60Waehler%60%0A%20%20%20%20%20%20the%20people%20who%20voted%20(*W%C3%A4hler*)%20and%20%60Gueltig%60%20the%20valid%20votes%20(*g%C3%BCltige%20Stimmen*).%20%60P01%60%2C%20%60P02%60%20and%0A%20%20%20%20%20%20so%20on%20count%20the%20votes%20for%20each%20party%3B%20more%20on%20them%20below.%0A%20%20%20%20-%20A%20column%20ending%20in%20%60p%60%20is%20a%20percentage%2C%20written%20with%20a%20decimal%20comma%20(%6064%2C9%60).%20So%20read%20the%20numbers%0A%20%20%20%20%20%20as%20decimal%20numbers.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%20Step%202%3A%20describe%20the%20layout%2C%20then%20read%0A%0A%20%20%20%20Four%20options%20describe%20what%20you%20just%20saw%3A%20skip%200%20lines%2C%201%20header%20row%2C%2012%20text%20columns%2C%20the%20rest%20decimal%0A%20%20%20%20numbers.%20%60BundeswahlleiterinReader%60%20is%20named%20after%20the%20federal%20returning%20officer%20(*Bundeswahlleiterin*).%0A%20%20%20%20Her%20results%20file%20sets%20the%20reader's%20default%20layout%3B%20these%20four%20options%20replace%20it.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20ColumnType%2C%0A%20%20%20%20OPTION_WAHL_HEADER_ROWS%2C%0A%20%20%20%20OPTION_WAHL_LABEL_COLUMNS%2C%0A%20%20%20%20OPTION_WAHL_SKIPROWS%2C%0A%20%20%20%20OPTION_WAHL_VALUE_TYPE%2C%0A)%3A%0A%20%20%20%20BERLIN_LAYOUT%20%3D%20%7B%0A%20%20%20%20%20%20%20%20OPTION_WAHL_SKIPROWS%3A%200%2C%0A%20%20%20%20%20%20%20%20OPTION_WAHL_HEADER_ROWS%3A%201%2C%0A%20%20%20%20%20%20%20%20OPTION_WAHL_LABEL_COLUMNS%3A%2012%2C%0A%20%20%20%20%20%20%20%20OPTION_WAHL_VALUE_TYPE%3A%20ColumnType.FLOAT%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20(BERLIN_LAYOUT%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20In%20tutorials%201%20and%202%2C%20%60peek%60%20listed%20the%20columns%20you%20can%20ask%20for.%20Give%20it%20the%20layout%2C%20and%20it%20does%20the%0A%20%20%20%20same%20for%20this%20file%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(AGH_2023_URL%2C%20BERLIN_LAYOUT%2C%20BundeswahlleiterinReader)%3A%0A%20%20%20%20BundeswahlleiterinReader.peek(AGH_2023_URL%2C%20options%3DBERLIN_LAYOUT)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(AGH_2023_URL%2C%20BERLIN_LAYOUT%2C%20BundeswahlleiterinReader%2C%20Feature%2C%20mloda)%3A%0A%20%20%20%20COLUMNS%20%3D%20%5B%22Bezirksname%22%2C%20%22WBezArt%22%2C%20%22WberIns%22%2C%20%22Waehler%22%2C%20%22Gueltig%22%2C%20%22P01%22%5D%0A%20%20%20%20_options%20%3D%20%7BBundeswahlleiterinReader%3A%20AGH_2023_URL%2C%20**BERLIN_LAYOUT%7D%0A%20%20%20%20_result%20%3D%20mloda.run_all(%0A%20%20%20%20%20%20%20%20%5BFeature(_name%2C%20options%3D_options)%20for%20_name%20in%20COLUMNS%5D%2C%0A%20%20%20%20%20%20%20%20compute_frameworks%3D%5B%22PyArrowTable%22%5D%2C%0A%20%20%20%20%20%20%20%20column_ordering%3D%22request_order%22%2C%0A%20%20%20%20)%0A%20%20%20%20agh_2023%20%3D%20_result%5B0%5D.to_pandas()%0A%20%20%20%20agh_2023%0A%20%20%20%20return%20COLUMNS%2C%20agh_2023%0A%0A%0A%40app.cell%0Adef%20_(agh_2023%2C%20mo)%3A%0A%20%20%20%20_kinds%20%3D%20agh_2023%5B%22WBezArt%22%5D.value_counts()%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%7Blen(agh_2023)%3A%2C%7D%20rows%20in%20%7Bagh_2023%5B%22Bezirksname%22%5D.nunique()%7D%20boroughs%3A%20%7B_kinds.get(%22W%22%2C%200)%3A%2C%7D%20polling%0A%20%20%20%20station%20districts%20and%20%7B_kinds.get(%22B%22%2C%200)%3A%2C%7D%20postal%20vote%20districts.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%20Step%203%3A%20a%20new%20election%20is%20a%20new%20URL%0A%0A%20%20%20%20Berlin%20published%20three%20more%20elections%20in%20the%20same%20layout%3A%0A%0A%20%20%20%20-%20**EU%202024%3A**%20the%20election%20to%20the%20European%20Parliament%20on%209%20June%202024.%0A%20%20%20%20-%20**BT%202025%3A**%20the%20election%20to%20the%20federal%20parliament%2C%20the%20*Bundestag*%20(BT)%2C%20on%2023%20February%202025.%0A%20%20%20%20-%20**AGH%202026%3A**%20the%20Abgeordnetenhaus%20election%20on%2020%20September%202026.%0A%0A%20%20%20%20Each%20one%20is%20a%20URL.%20The%20layout%20options%20stay%20as%20they%20are.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(AGH_2023_URL)%3A%0A%20%20%20%20ELECTIONS%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22AGH%202023%22%3A%20AGH_2023_URL%2C%0A%20%20%20%20%20%20%20%20%22EU%202024%22%3A%20%22https%3A%2F%2Fwww.wahlen-berlin.de%2Fwahlen%2FEU2024%2FAFSPRAES%2FDatenexport_EUROPAWAHL2024_Stimme_W_BE.csv%22%2C%0A%20%20%20%20%20%20%20%20%22BT%202025%22%3A%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22https%3A%2F%2Fwww.wahlen-berlin.de%2Fwahlen%2FBU2025%2Fafspraes%2FDatenexport_BUNDESTAGSWAHL2025_Zweitstimme_W_BE.csv%22%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%22AGH%202026%22%3A%20%22https%3A%2F%2Fwww.wahlen-berlin.de%2Fwahlen%2FBE2026%2FAFSPRAES%2Fagh%2FDatenexport_AGH2026_Zweitstimme_W_BE.csv%22%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20(ELECTIONS%2C)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20BERLIN_LAYOUT%2C%0A%20%20%20%20BundeswahlleiterinReader%2C%0A%20%20%20%20COLUMNS%2C%0A%20%20%20%20ELECTIONS%2C%0A%20%20%20%20Feature%2C%0A%20%20%20%20mloda%2C%0A%20%20%20%20pd%2C%0A)%3A%0A%20%20%20%20_frames%20%3D%20%5B%5D%0A%20%20%20%20for%20_election%2C%20_url%20in%20ELECTIONS.items()%3A%0A%20%20%20%20%20%20%20%20_options%20%3D%20%7BBundeswahlleiterinReader%3A%20_url%2C%20**BERLIN_LAYOUT%7D%0A%20%20%20%20%20%20%20%20_result%20%3D%20mloda.run_all(%0A%20%20%20%20%20%20%20%20%20%20%20%20%5BFeature(_name%2C%20options%3D_options)%20for%20_name%20in%20COLUMNS%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20compute_frameworks%3D%5B%22PyArrowTable%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20column_ordering%3D%22request_order%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20_frames.append(_result%5B0%5D.to_pandas().assign(election%3D_election))%0A%20%20%20%20elections%20%3D%20pd.concat(_frames%2C%20ignore_index%3DTrue)%0A%20%20%20%20_totals%20%3D%20elections.groupby(%22election%22%2C%20sort%3DFalse).agg(%0A%20%20%20%20%20%20%20%20rows%3D(%22WBezArt%22%2C%20%22size%22)%2C%20eligible_voters%3D(%22WberIns%22%2C%20%22sum%22)%2C%20voters%3D(%22Waehler%22%2C%20%22sum%22)%0A%20%20%20%20)%0A%20%20%20%20_totals.style.format(%22%7B%3A%2C.0f%7D%22)%0A%20%20%20%20return%20(elections%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20Four%20elections%2C%20one%20layout.%20When%20Berlin%20publishes%20the%20next%20one%2C%20add%20a%20line%20to%20%60ELECTIONS%60%20and%20run%20the%0A%20%20%20%20cells%20again.%0A%0A%20%20%20%20Two%20things%20do%20differ%20between%20elections%3A%0A%0A%20%20%20%20-%20The%20voting%20districts.%20Berlin%20redraws%20them%2C%20so%20the%20number%20of%20rows%20changes.%20The%2012%20boroughs%20stay%20the%0A%20%20%20%20%20%20same%2C%20so%20compare%20boroughs.%0A%20%20%20%20-%20Who%20may%20vote.%20At%20the%202024%20European%20election%20the%20minimum%20age%20was%2016%20and%20citizens%20of%20other%20EU%0A%20%20%20%20%20%20countries%20could%20vote.%20At%20the%202025%20Bundestag%20election%20the%20minimum%20age%20was%2018.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%20Pitfall%3A%20postal%20votes%20are%20in%20their%20own%20rows%0A%0A%20%20%20%20Turnout%20is%20the%20share%20of%20eligible%20voters%20who%20voted%3A%20%60Waehler%60%20divided%20by%20%60WberIns%60.%20Before%20you%20divide%2C%0A%20%20%20%20look%20at%20the%20two%20kinds%20of%20district%20in%20the%202023%20election%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(agh_2023)%3A%0A%20%20%20%20agh_2023.groupby(%22WBezArt%22)%5B%5B%22WberIns%22%2C%20%22Waehler%22%5D%5D.sum().style.format(%22%7B%3A%2C.0f%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(agh_2023%2C%20mo)%3A%0A%20%20%20%20_stations%20%3D%20agh_2023%5Bagh_2023%5B%22WBezArt%22%5D%20%3D%3D%20%22W%22%5D%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20Every%20eligible%20voter%20is%20listed%20in%20a%20polling%20station%20district%20(%60W%60).%20A%20person%20who%20votes%20by%20post%20is%0A%20%20%20%20counted%20as%20a%20voter%20in%20a%20postal%20vote%20district%20(%60B%60)%2C%20which%20lists%20no%20eligible%20voters.%20So%20a%20turnout%20per%0A%20%20%20%20row%20is%20wrong%3A%20in%20a%20%60W%60%20row%20the%20postal%20voters%20are%20missing%2C%20in%20a%20%60B%60%20row%20you%20divide%20by%20zero.%20Add%20up%20a%0A%20%20%20%20whole%20borough%2C%20or%20the%20whole%20city%2C%20before%20you%20divide.%20For%20the%20whole%20city%3A%0A%0A%20%20%20%20-%20Polling%20station%20rows%20only%20(too%20low)%3A%20%7B_stations%5B%22Waehler%22%5D.sum()%20%2F%20_stations%5B%22WberIns%22%5D.sum()%3A.1%25%7D%0A%20%20%20%20-%20All%20rows%20(the%20turnout%20the%20Landeswahlleiter%20reported)%3A%0A%20%20%20%20%20%20%7Bagh_2023%5B%22Waehler%22%5D.sum()%20%2F%20agh_2023%5B%22WberIns%22%5D.sum()%3A.1%25%7D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%20Try%20it%3A%20pick%20a%20borough%0A%0A%20%20%20%20The%20chart%20shows%20the%20borough's%20turnout%20in%20the%20four%20elections.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(elections%2C%20mo)%3A%0A%20%20%20%20_names%20%3D%20sorted(elections%5B%22Bezirksname%22%5D.unique())%0A%20%20%20%20borough%20%3D%20mo.ui.dropdown(%0A%20%20%20%20%20%20%20%20options%3D_names%2C%20value%3D%22Mitte%22%20if%20%22Mitte%22%20in%20_names%20else%20_names%5B0%5D%2C%20label%3D%22Borough%20(Bezirk)%22%0A%20%20%20%20)%0A%20%20%20%20borough%0A%20%20%20%20return%20(borough%2C)%0A%0A%0A%40app.cell%0Adef%20_(alt%2C%20borough%2C%20elections)%3A%0A%20%20%20%20_sums%20%3D%20(%0A%20%20%20%20%20%20%20%20elections%5Belections%5B%22Bezirksname%22%5D%20%3D%3D%20borough.value%5D%0A%20%20%20%20%20%20%20%20.groupby(%22election%22%2C%20sort%3DFalse)%5B%5B%22WberIns%22%2C%20%22Waehler%22%5D%5D%0A%20%20%20%20%20%20%20%20.sum()%0A%20%20%20%20%20%20%20%20.reset_index()%0A%20%20%20%20)%0A%20%20%20%20_sums%5B%22turnout%22%5D%20%3D%20_sums%5B%22Waehler%22%5D%20%2F%20_sums%5B%22WberIns%22%5D%0A%20%20%20%20alt.Chart(_sums%2C%20title%3Df%22Turnout%20in%20%7Bborough.value%7D%22).mark_bar().encode(%0A%20%20%20%20%20%20%20%20x%3Dalt.X(%22election%3AN%22%2C%20title%3DNone%2C%20sort%3DNone)%2C%0A%20%20%20%20%20%20%20%20y%3Dalt.Y(%22turnout%3AQ%22%2C%20title%3D%22Turnout%22%2C%20axis%3Dalt.Axis(format%3D%22%25%22))%2C%0A%20%20%20%20%20%20%20%20tooltip%3D%5B%22election%22%2C%20alt.Tooltip(%22turnout%3AQ%22%2C%20format%3D%22.1%25%22)%5D%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%20What%20the%20P%20columns%20are%0A%0A%20%20%20%20%60P01%60%20holds%20the%20votes%20for%20the%20party%20in%20first%20place%20on%20the%20ballot%20paper%2C%20%60P02%60%20for%20the%20second%2C%20and%20so%0A%20%20%20%20on.%20The%20place%20is%20not%20the%20party.%20Here%20is%20the%20share%20of%20the%20valid%20votes%20that%20went%20to%20%60P01%60%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(elections)%3A%0A%20%20%20%20_sums%20%3D%20elections.groupby(%22election%22%2C%20sort%3DFalse)%5B%5B%22P01%22%2C%20%22Gueltig%22%5D%5D.sum()%0A%20%20%20%20(_sums%5B%22P01%22%5D%20%2F%20_sums%5B%22Gueltig%22%5D).rename(%22P01%20share%20of%20valid%20votes%22).to_frame().style.format(%22%7B%3A.1%25%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20Each%20election%20has%20its%20own%20ballot%20paper.%20The%20files%20do%20not%20name%20the%20parties%3B%20the%20official%20results%20do.%0A%20%20%20%20Matched%20against%20them%2C%20%60P01%60%20is%20the%20Social%20Democrats%20(SPD)%20in%20the%202023%20file%20and%20the%20Greens%20(*GR%C3%9CNE*)%20in%0A%20%20%20%20the%202024%20file.%20The%20Berlin%20demo%20(see%20Next)%20shows%20the%20matching.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%20Where%20the%20data%20came%20from%0A%0A%20%20%20%20The%20files%20name%20neither%20a%20publisher%20nor%20a%20license.%20The%20website%20they%20come%20from%20does%3A%20its%20footer%20names%20the%0A%20%20%20%20Landeswahlleiter%20and%20the%20statistics%20office%20of%20Berlin%20and%20Brandenburg%20(*Amt%20f%C3%BCr%20Statistik*)%2C%20and%20its%0A%20%20%20%20imprint%20names%20the%20statistics%20office%20as%20publisher%20and%20states%20the%20terms.%20The%20copy%20on%20your%20disk%20records%0A%20%20%20%20when%20you%20downloaded%20each%20file.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(BundeswahlleiterinReader%2C%20ELECTIONS%2C%20elections%2C%20mo)%3A%0A%20%20%20%20def%20_retrieved(url)%3A%0A%20%20%20%20%20%20%20%20%23%20The%20copy%20Step%203%20read%3B%20a%20missing%20one%20means%20the%20cache%20was%20cleared%20since.%0A%20%20%20%20%20%20%20%20_copy%20%3D%20BundeswahlleiterinReader.retrieval(url)%0A%20%20%20%20%20%20%20%20return%20f%22%7B_copy.retrieved_at%3A%25Y-%25m-%25d%7D%22%20if%20_copy%20else%20%22not%20in%20the%20local%20cache%20any%20more%22%0A%0A%20%20%20%20_lines%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%22-%20**Publisher%3A**%20Der%20Landeswahlleiter%20f%C3%BCr%20Berlin%20%2F%20Amt%20f%C3%BCr%20Statistik%20Berlin-Brandenburg%22%2C%0A%20%20%20%20%20%20%20%20%22-%20**Website%3A**%20https%3A%2F%2Fwww.wahlen-berlin.de%22%2C%0A%20%20%20%20%20%20%20%20*(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22-%20**%7B_election%7D%3A**%20%7BELECTIONS%5B_election%5D%7D%2C%20retrieved%20%7B_retrieved(ELECTIONS%5B_election%5D)%7D%22%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20_election%20in%20elections%5B%22election%22%5D.unique()%20%20%23%20the%20elections%20Step%203%20read%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%5D%0A%20%20%20%20mo.md(%22%5Cn%22.join(_lines))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20The%20website%20names%20no%20open%20license.%20Its%20%5Bimprint%5D(https%3A%2F%2Fwww.wahlen-berlin.de%2Fimpressum.asp)%20allows%0A%20%20%20%20reuse%20with%20a%20source%20note%3A%20%22Vervielf%C3%A4ltigung%20und%20Verbreitung%2C%20auch%20auszugsweise%2C%20mit%20Quellenangabe%0A%20%20%20%20gestattet%22%20(copying%20and%20distribution%2C%20also%20of%20extracts%2C%20permitted%20with%20source%20attribution).%20So%20name%0A%20%20%20%20the%20publisher%20when%20you%20reuse%20the%20data%2C%20and%20say%20what%20you%20changed%3A%20here%2C%20you%20kept%20six%20columns%20and%20added%0A%20%20%20%20up%20the%20voting%20districts%20of%20each%20borough.%0A%0A%20%20%20%20%23%23%20Next%0A%0A%20%20%20%20The%20Berlin%20demo%20goes%20further%20with%20the%20same%20files%3A%0A%20%20%20%20party%20names%2C%20the%20people%20living%20in%20each%20voting%20district%20and%20an%20election%20night%20replayed.%20Run%20it%20with%0A%20%20%20%20%60uv%20run%20marimo%20edit%20demos%2Fberlin_wahl_2026_demo.py%60.%0A%20%20%20%20%5BReaders%5D(https%3A%2F%2Fgithub.com%2Fmloda-ai%2Fmloda-plugin-govdata%2Fblob%2Fmain%2Fdocs%2Freaders.md)%20describes%20the%0A%20%20%20%20election%20reader%20and%20its%20options.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
6bf032b7392f30a590ceace67b89ed00