Skip to main content

Build PyPI version fury.io DOI Downloads Python 3.5+ License: MIT

covidmx

Python API to get information about COVID-19 in México.

Requirements

more-itertools>=6.0.0
pandas>=0.25.2
Unidecode>=1.1.1
requests==2.21.0
xlrd==1.2.0
mapsmx==0.0.3
matplotlib==3.0.3
mapclassify==2.2.0
descartes==1.1.0

How to install

pip install covidmx

How to use

Dirección General de Epidemiología

The mexican Dirección General de Epidemiología has released open data about COVID-19 in México. This source contains information at the individual level such as gender, municipality and health status (smoker, obesity, etc). The package covidmx now can handle this source as default. Some variables are encoded as integers and the source also includes a data dictionary with all relevant information. When you pass clean=True (default option) returns the decoded data. You can also have access to the catalogue using return_catalogo=True and to the description of each one of the variables with return_descripcion=True. When you use some of this parameters, the API returns a tuple.

from covidmx import CovidMX

covid_dge_data = CovidMX().get_data()
raw_dge_data = CovidMX(clean=False).get_data()
covid_dge_data, catalogo_data = CovidMX(return_catalogo=True).get_data()
covid_dge_data, descripcion_data = CovidMX(return_descripcion=True).get_data()
covid_dge_data, catalogo_data, descripcion_data = CovidMX(return_catalogo=True, return_descripcion=True).get_data()

To get historical data use:

covid_dge_data = CovidMX(date='12-04-2020').get_data()

Default date format is %d-%m-%Y, but you can also use a particular format with:

covid_dge_data = CovidMX(date='2020-04-12', date_format='%Y-%m-%d').get_data()

Plot module

As of version 0.3.0, covidmx includes a module to create maps of different COVID-19 status at the national and state levels, with the possibility of including municipalities (using information of the Dirección General de Epidemiologia).

from covidmx import CovidMX

dge_plot = CovidMX().get_plot()

You can check available status and available states using:

dge_plot.available_states

array(['MÉXICO', 'CIUDAD DE MÉXICO', 'TAMAULIPAS', 'BAJA CALIFORNIA',
       'YUCATÁN', 'GUERRERO', 'BAJA CALIFORNIA SUR', 'JALISCO',
       'NUEVO LEÓN', 'SONORA', 'VERACRUZ DE IGNACIO DE LA LLAVE',
       'PUEBLA', 'CAMPECHE', 'GUANAJUATO', 'SAN LUIS POTOSÍ',
       'MICHOACÁN DE OCAMPO', 'COAHUILA DE ZARAGOZA', 'QUERÉTARO',
       'AGUASCALIENTES', 'TABASCO', 'HIDALGO', 'ZACATECAS', 'DURANGO',
       'CHIHUAHUA', 'CHIAPAS', 'SINALOA', 'QUINTANA ROO', 'MORELOS',
       'TLAXCALA', 'NAYARIT', 'OAXACA', 'COLIMA'], dtype=object)
dge_plot.available_status

['confirmados', 'negativos', 'sospechosos', 'muertos']

To plot a national map just use:

dge_plot.plot_map(status='confirmados')

If you want to include municipalities use:

dge_plot.plot_map(status='confirmados', add_municipalities=True)

You can pass a particular state filling the state argument with a valid name included in the available_states attribute:

dge_plot.plot_map(status='confirmados', state='CIUDAD DE MÉXICO', add_municipalities=True)
state='CIUDAD DE MÉXICO' state='JALISCO' state='MORELOS' state='MÉXICO'

Finally you can plot another interest variable (according to available_status attribute):

dge_plot.plot_map(status='sospechosos', add_municipalities=True)

You can save your maps using save_file_name:

dge_plot.plot_map(status='sospechosos', add_municipalities=True, save_file_name='sospechosos-nacional.png')

Serendipia

Serendipia publishes daily information of the mexican Secretaría de Salud about covid in open format (.csv). This api downloads this data easily, making it useful for task automation.

from covidmx import CovidMX

latest_published_data = CovidMX(source='Serendipia').get_data()

Then CovidMX instances a Serendipia class, searches the latest published data for both confirmed and suspects individuals and finally clean the data. Nevertheless, a more specific search can be conducted (see docs for details).

raw_data = CovidMX(source='Serendipia', clean=False).get_data()
confirmed = CovidMX(source='Serendipia', kind="confirmed").get_data()
suspects = CovidMX(source='Serendipia',kind="suspects").get_data()
particular_published_date = CovidMX(source='Serendipia', date='2020-04-10', date_format='%Y-%m-%d').get_data()

Cite as

Acknowledgments

Release information

0.3.1 (Current version)

  • 2020-06-01
  • Updated new urls from serendipia source. (Thanks to Mario Jimenez.)

0.3.0

  • 2020-04-26.
  • Includes a plot module at state and municipality leveles.
  • Includes a better handling of encodings. (Thanks to Mario Jimenez.)

0.2.5

0.2.4

  • 2020-04-16. The Dirección General de Epidemiología source renamed two columns:
    • HABLA_LENGUA_INDI -> HABLA_LENGUA_INDIG (column name and description are now homologated)
    • OTRA_CON -> OTRA_COM
    • Now the API can handle this change.

0.2.3

  • Now works with python3.5+.
  • Using clean=True returns encoded data instead of decoded data without cleaning columns (as works in 0.2.0 and 0.2.1).

0.2.1

  • Minor changes to README.

0.2.0

0.1.1

  • Minor changes to README.

0.1.0

First realease.

Metadata

Release files for covidmx 0.3.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 covidmx 0.3.1
File Size Uploaded
covidmx-0.3.1.tar.gz 13.3 kB Details

Built distribution (wheel)

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

Total release size: 26.7 kB

Release files / covidmx-0.3.1.tar.gz

Download URL covidmx-0.3.1.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
06e1844bf8dcfd5f1856d248dfe09d1fbbe69cc82c0c4c3fef4f2fb1d9e35e67
BLAKE2b-256 checksum
How to use checksums
de57ff042b585c9a7187425a4880b13c06c7e993bcfffdb37916e12b3ec612d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release files / covidmx-0.3.1-py3-none-any.whl

Download URL covidmx-0.3.1-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4803b970ebde89705e6c76889e8ac057ee8494995f48e3c238a9a72022a93e54
BLAKE2b-256 checksum
How to use checksums
b09cf2102a27f95aefe89e71af96039719ea0677b3acd317a00462e8db10f2d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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