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

Download files

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

Source Distribution

mad_ssb-0.1.2.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

mad_ssb-0.1.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file mad_ssb-0.1.2.tar.gz.

File metadata

  • Download URL: mad_ssb-0.1.2.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for mad_ssb-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2b84508ae4361a8146b6d191a25b23d8f90bfef0d20bbb6ddb6ca000aefba8ec
MD5 2b01abb44845bfcc4d52202b200e84bf
BLAKE2b-256 dccb6fc2825042e97d7f66a944c5927581450bd5b507fa7fd7e2cd0c9f6b44f5

See more details on using hashes here.

File details

Details for the file mad_ssb-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mad_ssb-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for mad_ssb-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 aadccaafb7d998a2aca4ce78e00431ad3dd29563a67c3ed2003a5af9081a6872
MD5 2cbd4c593a766e00e842b47be6e13bf9
BLAKE2b-256 f4b97fb34e243d2ef71996c6d0ec0b66e8d9697898c3bee532ca4af506c55a02

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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