AzulGarza / covidmx

Python API to get information about COVID-19 in México.
MIT License
19 stars 7 forks source link
api coronavirus covid-19 mexico mexico-maps pip python

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)

0.3.0

0.2.5

0.2.4

0.2.3

0.2.1

0.2.0

0.1.1

0.1.0

First realease.