Skip to main content

denstatbank

denstatbank

A python wrapper to Statistics Denmark's Databank API. The package allows you to easily gather and analyse data on a variety of topics made available by Statistics Denmark.

The package provides a simple interface for professional statisticians, academics, policymakers, students, journalists and anyone interested in quantitative facts about Denmark.

Installation

The package is listed on pypi - the python package index, and can be installed with pip as:

pip install --upgrade denstatbank

Usage

A walkthrough example

Let us walkthrough a quick example of how to query for data on a specific topic. The first step is to instantiate the client. This is easily done with the following two lines of code.

>>> from denstatbank import StatBankClient
>>> sbc = StatBankClient(lang='en')

Now, let's find a table to get data from the databank. The tables method provides a list of all tables containing data currently available in the databank. Let's take a look at the first table.

>>> tdf = sbc.tables()
>>> tdf.iloc[0]
id                                                  FOLK1A
text            Population at the first day of the quarter
unit                                                number
updated                                2020-02-11T08:00:00
firstPeriod                                         2008Q1
latestPeriod                                        2020Q1
active                                                True
variables         [region, sex, age, marital status, time]

All data tables have values associated with certain variables specific to the table. The population table that we shall look at has five such variables with the names you see above. The variables themselves have a list of valid values. One quick way of finding acceptable values for the variables is by using the tableinfo method as follows:

>>> vdf = sbc.tableinfo('folk1a', variables_df=True)
>>> years = vdf[vdf['variable']=='time']['id'].tolist()

We have now extracted the list of all acceptable values for the variable 'time'. Now, we need to put this inside a dictionary where the dictionary key is the variable name (in Danish, so 'time' becomes 'tid'). The client has a method called variable_dict() which does this for you.

>>> tid = sbc.variable_dict(code='tid', values=years)

Finally, we query the data by passing the table id and the variables dictionary as a keyword arguments. The dictionary must be placed inside a list as the method can accept more than one variables dictionary.

>>> df = sbc.data(table_id='folk1a', variables=[tid])
>>> df.head()
          Population at the first day of the quarter by Indhold and time
tid                                                                   
2008Q1                                            5475791             
2008Q2                                            5482266             
2008Q3                                            5489022             
2008Q4                                            5505995             
2009Q1                                            5511451

And there we have the population data. Let us quickly plot it to get a feel for the data.

>>> df.plot(style='o-', figsize=(10, 6))

denstatbank uses the pandas python library to facilitate the handling of data. Pandas is a fast, popular and powerful library used for data analysis and manipulation. It is therefore well suited to be used with this package. There are plenty of resources available to learn from if you are new to pandas. I would highly recommend this book by the creator of the pandas himself.

Documentation

The detailed package documentation can be found here.

The official Databank API documentation can be found here.

Metadata

Release files for denstatbank 0.8.1

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

Source distribution (sdist)

Source distribution for denstatbank 0.8.1
File Size Uploaded Provenance
denstatbank-0.8.1.tar.gz 9.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for denstatbank 0.8.1
File Interpreter ABI Platform
denstatbank-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.0 kB

Release files / denstatbank-0.8.1.tar.gz

Download URL denstatbank-0.8.1.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a3e9a8d15506929be45312b32f480297b5c64ec4ab71439e643e95206fd58222
BLAKE2b-256 checksum
How to use checksums
d41f1e9618f266f52125352287fd0750f81ace11489bbfd9812a53f963f3a8c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.1

Release files / denstatbank-0.8.1-py3-none-any.whl

Download URL denstatbank-0.8.1-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f006e80b623f99f103fc78b1052baa5c70b51ca94bf0e98d398c7577a8576181
BLAKE2b-256 checksum
How to use checksums
27e47c64b3636314942fe2a5cd6df3e1e861898ff676965d8ace987532817d2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.1

Security for denstatbank 0.8.1

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