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.1.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.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mad_ssb-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 677f2c43b793df788a7934757e01f900ac636d2b63e238ec0ffc2ff331b5f970
MD5 e99d4cfdde4702878a23e1f092d7a25b
BLAKE2b-256 983b5406939e3ad71afd3745eefe95ad5c549379e34685df802fc785ce55b4d5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mad_ssb-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6e435f1db1a5a0c10f6648ad4f996ea5321e4cc8163f469a8488b733fef39117
MD5 7dd9a5bcc74d58185c3a8631fd772dfc
BLAKE2b-256 68f47c5b0edc322df2656b76a070315794773e622a6cc161a314a55df97b9274

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

This release

0.1.1 This release

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