Skip to main content

mad-ssb

PyPI version Python versions License

Turn municipal-level tables exported from Statistics Norway (Statistikkbanken / SSB) into tidy pandas.DataFrames that are ready for data analysis.

SSB Excel exports are formatted for humans rather than for computation: they start with a banner of title/metadata rows, end with footnotes, lay out data horizontally (one column per year) and encode missing values as the strings '.' and '..'. mad-ssb returns a single long-format table, adds a municipal ID number column, as well as does other basic clean up tasks to get to a decent starting point for creating SSB datasets for analysis.

Installation

pip install mad-ssb

or with uv:

uv add mad-ssb

Requires Python 3.11+ and pandas 3.0+.

Quick start

>>> from mad_ssb import read_ssb
>>> df = read_ssb("municipal_table.xlsx")
>>> df.head()
    MID  year  outcome
0  0301  2010      123
1  0301  2011      456
2  0302  2010       78
  • Data columns (years) are stacked into a single year/outcome pair.
  • The municipal ID is extracted into its own MID column.
  • Optional: rename the index (metadata) columns with non_year_col_names, e.g. read_ssb(path, non_year_col_names=["region"]). Use dtype="float" when the table contains decimals or NA that integers cannot hold.

How it works

mad-ssb is a small pipeline of composable helpers (all exposed as public API):

Function What it does
find_ssb_table_header_row Find where the real table header starts (skip the banner)
find_ssb_table_end Find where the data stops (skip the footnotes)
find_non_year_columns Identify the index/metadata columns left of the first year
rank_non_year_cols Order index columns coarse-to-fine for a clean hierarchy
centre_on_mid_col Split "0301 Oslo" into MID (0301) and promote it
stack_ssb_table Stack wide year columns into year/outcome
read_ssb Main entry point that drives the helpers above

License

MIT

Metadata

Release files for mad-ssb 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mad-ssb 0.1.2
File Size Uploaded Provenance Actions
mad_ssb-0.1.2.tar.gz 12.2 kB Without provenance Details for mad_ssb-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mad-ssb 0.1.2
File Interpreter ABI Platform Actions
mad_ssb-0.1.2-py3-none-any.whl Python 3 none any Details for mad_ssb-0.1.2-py3-none-any.whl

Total release size: 21.5 kB

Release files / mad_ssb-0.1.2.tar.gz

Download URL mad_ssb-0.1.2.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2b84508ae4361a8146b6d191a25b23d8f90bfef0d20bbb6ddb6ca000aefba8ec
BLAKE2b-256 checksum
How to use checksums
dccb6fc2825042e97d7f66a944c5927581450bd5b507fa7fd7e2cd0c9f6b44f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / mad_ssb-0.1.2-py3-none-any.whl

Download URL mad_ssb-0.1.2-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aadccaafb7d998a2aca4ce78e00431ad3dd29563a67c3ed2003a5af9081a6872
BLAKE2b-256 checksum
How to use checksums
f4b97fb34e243d2ef71996c6d0ec0b66e8d9697898c3bee532ca4af506c55a02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for mad-ssb 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page