Package: covid19sweden
Web Scraper of COVID-19 data for SwedenPython packagecovid19swedenprovides access to mortality and COVID-19 data of Sweden.The data is scraped from:https://scb.se/om-scb/nyheter-och-pressmeddelanden/overdodligheten-fortsatter-att-sjunka-efter-toppen-i-april/Setup and usageInstall frompipwithpipinstallcovid19swedenCurrently available functions aredeaths()fetching number of deathsfohm.regions()andfohm.municipalities()fetching Covid-19 statistics in regions and municipalities.Package is regularly updated. Update withpipinstall--upgradecovid19swedenCovid-19 DeathsFetch Covid-19 deaths by weeks usingimportcovid19swedenasSEx=SE.covid_deaths(level=1)The data can be acquired split into regions or municipalities using granularity variablelevelx_regions=SE.covid_deaths(level=2)x_municipalities=SE.covid_deaths(level=3)DeathsOverall deaths in Sweden can be fetched such asimportcovid19swedenasSWEdata=SWE.deaths()The function returns pandas dataframe with the columns being years and rows being deaths of each age andLevelLevel is a setting for granularity of dataCountry level (default)State levelMunicipality levelimportcovid19swedenasSWE# country levelx1a,x1b,x1u=SWE.deaths(level=1)# state levelx2a,x2b,x2u=SWE.deaths(level=2)# municipality levelx3a,x3b,x3u=SWE.deaths(level=3)By default the level is 1. Level settings can be implicitly changed in the function.WeeklyWeekly is a setting of time axis of the data.True- data are by weeksFalse- data are by daysDefault isFalse, data by days.importcovid19swedenasSWE# weeklyxa,xb,xu=SWE.deaths(weekly=True)Given setting will implicitly changeper_gender_age = True, even though default isFalse. This behavior is described at sectionVerbose and alt.Setting ofweeklycan be also implicitly changed if no data is available for given settings.Per gender or ageThe settingsper_gender_ageis controlling the deaths to be splitted into groups by gender (M,F) and age groups (mostly 0-64,65-79,80-89,90+).importcovid19swedenasSWE# weeklyxa,xb,xu=SWE.deaths(per_gender_age=True)Setting ofper_gender_agecan be implicitly changed if no data is available for given settings.Verbose and altNot for all the combinations of the parameters the data is available. E.g. forlevel = 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 fornot per_gender_age, use themif data is available fornot weekly, use themif data is available fornot per_gender_age,not_weekly, use themImplicit parameter change is announced on stdout. It can be switched off by settingverbose = False.Sometimes multiple datasets with slight difference (or two conversions) are available. This is announced on stdout. Choosing an alternative data is done withalt = True.Covid-19 in regions and municipalitiesTo fetch data in regions and municipalities, typeimportcovid19swedenasSWEregions=SWE.fohm.regions()municipalities=SWE.fohm.municipalities()Only parameter for both functions is optionalfilename,
that saves the data to csv output file.SWE.fohm.municipalities(filename="output.csv")CommitWith a single call all the data handlers are called and their outputs as well as common input (xlsx file) is stored.Commitis stored directorycommit_YYMMDD(incwd) unless explicitly specified.importcovid19swedenasSWESWE.commit()# store all filesExplicit specification of directory is done withSWE.commit("/var/latest_data")Function will try to create the folder. It fails on existing files of the same name. Overwriting must be enabledSWE.commit("/var/latest_data",overwrite=True)TODO:add fohm to commitContributionDeveloped byMartin Benes.Join onGitHub.