Skip to main content

Web Scraper of COVID-19 data for Sweden

Python package covid19sweden provides access to mortality and COVID-19 data of Sweden.

The data is scraped from:

Setup and usage

Install from pip with

pip install covid19sweden

Currently available functions are

  • deaths() fetching number of deaths
  • fohm.regions() and fohm.municipalities() fetching Covid-19 statistics in regions and municipalities.

Package is regularly updated. Update with

pip install --upgrade covid19sweden

Covid-19 Deaths

Fetch Covid-19 deaths by weeks using

import covid19sweden as SE

x = SE.covid_deaths(level = 1)

The data can be acquired split into regions or municipalities using granularity variable level

x_regions = SE.covid_deaths(level = 2)
x_municipalities = SE.covid_deaths(level = 3)

Deaths

Overall deaths in Sweden can be fetched such as

import covid19sweden as SWE

data = SWE.deaths()

The function returns pandas dataframe with the columns being years and rows being deaths of each age and

Level

Level is a setting for granularity of data

  1. Country level (default)
  2. State level
  3. Municipality level
import covid19sweden as SWE

# country level
x1a,x1b,x1u = SWE.deaths(level = 1)
# state level
x2a,x2b,x2u = SWE.deaths(level = 2)
# municipality level
x3a,x3b,x3u = SWE.deaths(level = 3)

By default the level is 1. Level settings can be implicitly changed in the function.

Weekly

Weekly is a setting of time axis of the data.

  • True - data are by weeks
  • False - data are by days

Default is False, data by days.

import covid19sweden as SWE

# weekly
xa,xb,xu = SWE.deaths(weekly = True)

Given setting will implicitly change per_gender_age = True, even though default is False. This behavior is described at section Verbose and alt.

Setting of weekly can be also implicitly changed if no data is available for given settings.

Per gender or age

The settings per_gender_age is controlling the deaths to be splitted into groups by gender (M,F) and age groups (mostly 0-64,65-79,80-89,90+).

import covid19sweden as SWE

# weekly
xa,xb,xu = SWE.deaths(per_gender_age = True)

Setting of per_gender_age can be implicitly changed if no data is available for given settings.

Verbose and alt

Not for all the combinations of the parameters the data is available. E.g. for level = 3, only daily data without gender and age distinguishing is available. Hence to minimize error rate, implicit parameter changes are introduced.

If the data for given settings is not available, a set of rules is applied to reach data:

  • if data is available for not per_gender_age, use them
  • if data is available for not weekly, use them
  • if data is available for not per_gender_age, not_weekly, use them

Implicit parameter change is announced on stdout. It can be switched off by setting verbose = False.

Sometimes multiple datasets with slight difference (or two conversions) are available. This is announced on stdout. Choosing an alternative data is done with alt = True.

Covid-19 in regions and municipalities

To fetch data in regions and municipalities, type

import covid19sweden as SWE

regions = SWE.fohm.regions()
municipalities = SWE.fohm.municipalities()

Only parameter for both functions is optional filename, that saves the data to csv output file.

SWE.fohm.municipalities(filename = "output.csv")

Commit

With a single call all the data handlers are called and their outputs as well as common input (xlsx file) is stored. Commit is stored directory commit_YYMMDD (in cwd) unless explicitly specified.

import covid19sweden as SWE
SWE.commit() # store all files

Explicit specification of directory is done with

SWE.commit("/var/latest_data")

Function will try to create the folder. It fails on existing files of the same name. Overwriting must be enabled

SWE.commit("/var/latest_data", overwrite = True)

TODO:

  • add fohm to commit

Contribution

Developed by Martin Benes.

Join on GitHub.

Metadata

Release files for covid19sweden 0.2.2

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

Source distribution (sdist)

Source distribution for covid19sweden 0.2.2
File Size Uploaded Provenance
covid19sweden-0.2.2.tar.gz 42.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 83.0 kB

Release files / covid19sweden-0.2.2.tar.gz

Download URL covid19sweden-0.2.2.tar.gz
Size 42.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dcb8c58aecc7dbf0c9aaf9696f0cb3ee4d8251e69483b665fd370acc8e0373d7
BLAKE2b-256 checksum
How to use checksums
9b15b8af1a85fa8926d26937951a069055efd9ab9c15f1185154c2461e932dd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

Release files / covid19sweden-0.2.2-py3-none-any.whl

Download URL covid19sweden-0.2.2-py3-none-any.whl
Size 40.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bde74994f3296a3278c8bd4d57a689f9a5f3e7f3a74da90e27aebe1831bcb69a
BLAKE2b-256 checksum
How to use checksums
1dbeba868a9c3e9fa0f1fde5c97bb31bc2431d315a31e4f3dc8411530b5ce436
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

Security for covid19sweden 0.2.2

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