Public
Edited
Nov 2
Importers
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
stimmen
SELECT a.Gebietsnummer as AGS, a.Gebietsname as Kreis, a.Gruppenname as Partei, a.Prozent, c.Wahlberechtigte, d.Wählende, e.Ungültige, f.Gültige, d.Wählende/c.Wahlberechtigte*100 as Prozent_Wahlbeteiligung, e.Ungültige/d.Wählende*100 as Prozent_Ungültig
FROM stimmen a
INNER JOIN (
SELECT Gebietsname, MAX(Prozent) Prozent
FROM stimmen
WHERE Gebietsart = 'Kreis' AND Gruppenart = 'Partei'
GROUP BY Gebietsname
) b ON a.Gebietsname = b.Gebietsname AND a.Prozent = b.Prozent
INNER JOIN (
SELECT Gebietsname, SUM(Anzahl) as Wahlberechtigte
FROM stimmen
WHERE Gebietsart = 'Kreis' AND Gruppenart = 'System-Gruppe' AND Gruppenname = 'Wahlberechtigte'
GROUP BY Gebietsname
) c ON a.Gebietsname = c.Gebietsname
INNER JOIN (
SELECT Gebietsname, SUM(Anzahl) as Wählende
FROM stimmen
WHERE Gebietsart = 'Kreis' AND Gruppenart = 'System-Gruppe' AND Gruppenname = 'Wählende'
GROUP BY Gebietsname
) d ON a.Gebietsname = d.Gebietsname
INNER JOIN (
SELECT Gebietsname, SUM(Anzahl) as Ungültige
FROM stimmen
WHERE Gebietsart = 'Kreis' AND Gruppenart = 'System-Gruppe' AND Gruppenname = 'Ungültige'
GROUP BY Gebietsname
) e ON a.Gebietsname = e.Gebietsname
INNER JOIN (
SELECT Gebietsname, SUM(Anzahl) as Gültige
FROM stimmen
WHERE Gebietsart = 'Kreis' AND Gruppenart = 'System-Gruppe' AND Gruppenname = 'Gültige'
GROUP BY Gebietsname
) f ON a.Gebietsname = f.Gebietsname
Insert cell
stimmen = {
// Die Daten wurden vom Open-Data Portal der Landeswahlleiterin am 12.06.2024 abgerufen:
// https://www.bundeswahlleiterin.de/europawahlen/2024/ergebnisse/opendata/ew24/csv/kerg2.csv
// Da im Open-Data Portal kein CORS-Header gesetzt wird, können wir im Notebook leider nicht direkt mit der URL arbeiten. Ich habe die Datei deshalb heruntergeladen und im Notebook angehangen.

// Wie es sich gehört für eine deutsche Behörde ist die CSV-Datei auch unnötig komplex aufgebaut, damit man sie auch möglichst umständlich parsen muss. Die eigentliche Kopfzeile befindet sich in der 10. Zeile, davor befinden sich Metadaten.
const csvString = await FileAttachment("kerg2.csv").text();
// Wir trennen den Dateiinhalt nach Zeilenumbrüchen, und ignorieren alles vor der 10. Zeile
return d3
.dsvFormat(";")
.parse(csvString.split("\n").slice(9).join("\n"), (d, i) => ({
...d,
Prozent: +d.Prozent.replace(",", "."),
Anzahl: +d.Anzahl
}));
}
Insert cell
de = {
// Quelle der Landkreisgeometrien: GeoBasis-DE / BKG 2023
// https://www.zensus2022.de/DE/Presse/Grafik/shapefile.html
// Die im Link enthaltene Shape-Datei "VG250_KRS" wurden mit mapshaper.org in WGS84 reprojeziert. Die Geometrien wurden vereinfacht, um die Darstellung im Browser zu beschleunigen.
return FileAttachment("VG250_KRS (1)@1.json").json();
}
Insert cell
Insert cell
Insert cell
Insert cell
import { Swatches } from "@d3/color-legend"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more