Skip to content

Hospitalizations and Deaths

How to call the data

In your browser

Simply type https://covid19data.dk/coviddata in your browser and the API will deliver the data as jsonto your browser. You can then save the data to disk by simply using cntr/cmd + s.

Using R

In R you can leverage the jsonlitepackage and call the api with a few lines of code:

library(jsonlite)

url <- "https://covid19data.dk/coviddata"
df  <-  fromJSON(url)

Using Python

In Python you can use the requests and the pandas libraries to read in the data:

import requests
import pandas as pd

url = 'https://covid19data.dk/coviddata'

resp = requests.get(url)
jsondata = resp.json()

pd.DataFrame(jsondata)

Source of the data

The data is automatically parsed from the Danish Broadcasting Associations website, specifically the article called Status på coronavirus lige nu.

The article contains several interactive graphics embedded from Infogram and it is this data that the API presents.

So, I no longer update the data myself, I simply read it of DR's website. As long as they keep updating their data, this API will also be up to date.

Data collection

I have built a few functions in Python that read the html of the interactive graphics mentioned above and then parses the data from the raw underlying text.

It then saves the data to a local file on the API server. Everytime there is a request to the API, then the code checks to see how old the file on disk is, and if it is older than 10 minutes, then the data gets rescrabed and stored.

It is this local file that is served when the API is called.