Skip to main content

German Election Database (GERDA): lightweight Python loader for the GERDA datasets.

Project description

gerda

Lightweight Python loader for the German Election Database (GERDA). Downloads and returns pandas DataFrames for German federal, state, local, mayoral, county, and European Parliament elections (1953–2025), plus boundary crosswalks. Python port of the gerda R package.

Install

pip install git+https://github.com/hhilbig/gerda-py
pip install "gerda[polars] @ git+https://github.com/hhilbig/gerda-py"

A PyPI release is planned; once published, pip install gerda will work.

Requires Python 3.11+.

Use

import gerda

# List all 39 datasets
gerda.datasets()

# Load federal county-level results
df = gerda.load("federal_cty_harm")

# Load harmonized municipal data and convert to polars
df = gerda.load("federal_muni_harm_25", as_polars=True)

# Force a fresh download (bypass cache)
df = gerda.load("federal_cty_harm", refresh=True)

Files are downloaded from the GERDA data repository and cached in a platform-specific user cache directory: ~/.cache/gerda/ on Linux, ~/Library/Caches/gerda/ on macOS, %LOCALAPPDATA%\gerda\Cache\gerda on Windows. The exact path is available at runtime:

from gerda.cache import cache_dir
print(cache_dir())

Cached files keep their original dataset names (e.g. federal_cty_harm.rds), so it's safe to inspect or prune the cache by hand. RDS files are read with pyreadr; column dtypes (notably string AGS codes with leading zeros) are preserved automatically.

Party crosswalk

Map GERDA party names to ParlGov attributes:

import gerda

gerda.party_crosswalk(["cdu", "spd", "linke_pds"], "left_right")
# 0    6.2503
# 1    3.6451
# 2    1.2152
# dtype: float64

gerda.party_crosswalk(["cdu", "afd"], "family_name_short")
# 0      chr
# 1    right

See gerda.crosswalk.destinations() for the full list of 21 destination columns (party names, family, ideology scales, identifiers).

Scope

This package wraps three of the R package's nine functions: load, datasets, and party_crosswalk. The bundled INKAR / Zensus 2022 tables and their merge helpers (add_gerda_covariates, add_gerda_census) are intentionally not ported — Python users can do their own merges. If you need them, use the R package.

Citation

Heddesheimer, Sichart, Wiedemann, and Hilbig. "German Elections Database (GERDA)." Scientific Data (2025). doi:10.1038/s41597-025-04811-5

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gerda-0.1.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gerda-0.1.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file gerda-0.1.0.tar.gz.

File metadata

  • Download URL: gerda-0.1.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gerda-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2ab6b1cf55d46225c5e2338f89e94dc5167f7483aefec525c45eb9143640c372
MD5 aaaa82b73815a2bda10417cb05a2cc00
BLAKE2b-256 48f3ffde85a44ed57bb65c168cf0d9679c72635a202b429839a243fd1894665a

See more details on using hashes here.

File details

Details for the file gerda-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gerda-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gerda-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 26b727862b3ff51504e44cc459b93824ccbfe34e7509b08e42406cbdffadfd86
MD5 0375e76ed540014a2783737e4acad12a
BLAKE2b-256 aaab36268da9b12448186123d42aa86fdd84c4ee99afe445158eedd4037620d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page