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.0.tar.gz (11.9 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.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mad_ssb-0.1.0.tar.gz
  • Upload date:
  • Size: 11.9 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.0.tar.gz
Algorithm Hash digest
SHA256 cebe8af2cae2ee76fc4308495d43959b7252d464d9c0b53298a7a87732087a58
MD5 59a6ced8ccfc7939c6d1b75f79353216
BLAKE2b-256 5a533103940863f2f8c371053262dfaaed8c96b5950453da82bfe6cfffe35e5d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mad_ssb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a618176f786a44fcf8298ab647043c9dea3872430c6081eeed0035bfee9229d8
MD5 7fc6fb29331a7d7c1eac84f375a136ca
BLAKE2b-256 b14edb253a6b338d2b75b1d8c50cbcd7f4316914a14094a9e7d71ecce9fed1a6

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

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