Examples for using open data
The data are made available as datasets on avoindata.fi. Each dataset consists of the data in .csv format and metadata in .json format. The data can be used manually for example in Excel files or programmatically with various programming languages.
Manual use of the data
Both the data and the metadata can be downloaded by clicking on the Downlink link on the front page for the dataset. The data can be imported into Excel or some other program. The data are separated with commas, and the character encoding used is UTF-8.
Programmatic use of the data
The open data is machine readable. Avoindata.fi offers various alternatives for reading the data.
The following examples involve looking up data on labour market subsidy payments partially funded by the municipalities.
Accessing machine-readable data directly
The functions available in the ckanr (cran.r-project.org)(Opens in a new tab) library and in the ckanapi (pypi.org) (Opens in a new tab)library can be used to read data from avoindata.fi directly.
Example using R:
library(ckanr)
library(readr)
library(jsonlite)
# Define CKAN
ckanr_setup(url = "https://avoindata.fi/data/fi/")
# Look up all Kela datasets
x <- package_search(q = "Kela (Kansaneläkelaitos)")
# Retrieve the resources for the first dataset
resources <- x$results[[1]]$resources
# Download the data
dat <- read_csv(resources[[1]]$url)
# Download the metadata
meta <- fromJSON(txt = resources[[2]]$url)
Using the DataStore interface to retrieve data with an SQL search
The R library at ckanr (cran.r-project.org) (Opens in a new tab)also includes functions for performing a query using the DataStore interface. When using Python, the urllib (docs.python.org)(Opens in a new tab) library must be used.
Example using R:
library(ckanr)
library(glue)
# Define CKAN
ckanr_setup(url = "https://avoindata.fi/data/fi/")
# Look up the correct dataset whose title ends with the word ‘kunnittain’ (by municipality)
x <- package_search(q = "Kela (Kansaneläkelaitos)", fq = "title:kunnittain$")
# Look up the data ID for the dataset
ID <- x$results[[1]]$resources[[1]]$id
# Look up the total amount of labour market subsidies paid over a period of one year in Helsinki and the number of beneficiaries
res <- ckanr::ds_search_sql(
sql = glue("
SELECT
kunta_nimi,
vuosikuukausi,
sum(maksettu_eur) as sum_maksettu_eur,
sum(saaja_lkm) as sum_saaja_lkm
FROM \"{ID}\"
WHERE kunta_nimi = 'Helsinki'
AND aikatyyppi = 'Kuukausi'
AND tyomarkkinatukipaiva_luokka = 'Yhteensä'
GROUP BY vuosikuukausi, kunta_nimi"),
as = "table")
res$records
# equivalent to the following report: http://raportit.kela.fi/linkki/95155785