Wolfram Research

Function Repository Resource:

MexicoCOVID19Data

Source Notebook

Import data from the Dirección General de Epidemiología website

Contributed by: Carlos Muñoz

ResourceFunction["MexicoCOVID19Data"][]

retrieves COVID-19 data from the Dirección General de Epidiemología website.

Details and Options

ResourceFunction["MexicoCOVID19Data"] retrieves fresh data from the web. Therefore, it is not necessary to call this function unless the data has been updated by the Dirección General de Epidemiología. You can store this data as a variable to avoid repeated downloads.
Most columns are self explanatory. Details of each column can be imported from the dataset's website with ResourceFunction["MexicoCOVID19Data"]["Descriptors"], although column names and types might be different. For example, the original data for "Hospitalized" is from the column for "TIPO_PACIENTE" and the values were modified to True for "hospitalizado" (if they were hospitalized) and False for "ambulatorio" (if they were sent home).

Examples

Basic Examples (6) 

Retrieve the dataset:

In[1]:=
mexicoCOVIDdata = ResourceFunction["MexicoCOVID19Data"][]
Out[1]=

Compare the age distributions between male and female cases:

In[2]:=
PairedHistogram[Sequence @@ (Normal@#[Values]), ChartLabels -> Normal@#[Keys], Sequence[PlotLabel -> "age distribution", PlotTheme -> "Business"]] &@
 mexicoCOVIDdata[GroupBy["Sex"], Select[! MissingQ[#Age] &], "Age"]
Out[2]=

Plot a geographical heat map showing the number of cases per federal entity:

In[3]:=
GeoRegionValuePlot[
 Normal@mexicoCOVIDdata[Counts, "PlaceOfMedicalAttention"]]
Out[3]=

Plot the daily number of recorded cases:

In[4]:=
dailyCasesTimeSeries = TimeSeries@
   KeyValueMap[{#1, #2} &, Normal@mexicoCOVIDdata[Counts, "DateOfAdmissionHospital"]];
dailyCasesAccumulate = Accumulate@dailyCasesTimeSeries;
dailyCasesMA = MovingAverage[dailyCasesTimeSeries, 7];
In[5]:=
DateListPlot[{dailyCasesTimeSeries, dailyCasesMA}, FrameLabel -> {None, "Number of cases per day"}, PlotLegends -> {"time series", "moving average"}]
Out[5]=

Plot the total number of recorded cases over time:

In[6]:=
DateListPlot[dailyCasesAccumulate, FrameLabel -> {None, "Number of cases per day"}]
Out[6]=

Look at and sort by the most common comorbidities:

In[7]:=
Reverse@SortBy[
  Tally@DeleteMissing@Flatten@mexicoCOVIDdata[All, "Comorbidities"], Last]
Out[7]=

Scope (2) 

Some federal entities have a much larger population and this can make it difficult to see differences between low-population entities. To visualize the number of recorded cases relative to the entity’s population, you can plot the number of COVID-19 cases per 1000 people:

In[8]:=
GeoRegionValuePlot[
 KeyValueMap[#1 -> (1000*#2/
       QuantityMagnitude[
        AdministrativeDivisionData[#1, "Population"]]) &, Normal@mexicoCOVIDdata[Counts, "PlaceOfMedicalAttention"]]]
Out[8]=

Look at the time series of a specific state:

In[9]:=
stateTS = TimeSeries@
   KeyValueMap[{#1, #2} &, Normal@mexicoCOVIDdata[
      Select[#PlaceOfMedicalAttention == Entity["AdministrativeDivision", {"Oaxaca", "Mexico"}] &] /*
        Counts, "DateOfAdmissionHospital"]];
stateTSMA = MovingAverage[stateTS, 7];
DateListPlot[{stateTS, stateTSMA}, FrameLabel -> {None, "Number of cases per day"}, PlotLegends -> {"time series", "moving average"}, PlotLabel -> Entity["AdministrativeDivision", {"Oaxaca", "Mexico"}]]
Out[10]=

Options (1) 

See the descriptions of the columns from the original dataset:

In[11]:=
ResourceFunction["MexicoCOVID19Data"]["Descriptors"]
Out[11]=
In[12]:=
datosCOVIDMexico = ResourceFunction["MexicoCOVID19Data"]["Language" -> "Spanish"]
Out[12]=

Resource History

Source Metadata

Related Resources

Author Notes

This was made to work with data from September 11, 2020. Future changes in data may affect the results of running this function.

License Information