Skip to main content
added remarks
Source Link
gwr
  • 13.6k
  • 2
  • 48
  • 82

I would like to expand upon Roman's suggestion to download data from the European Center for Disease Control (ECDC). The data will be stored in an Excel file at certain location with a filename, that includes the date. We can use that and build a list of associations from that.

$data = Module[
   {
     strDate = DateString[Today, "ISODate" ],
     strURL = "https://www.ecdc.europa.eu/sites/default/files/documents/",
     strFileBaseName = "COVID-19-geographic-disbtribution-worldwide-",
     strSuffix = ".xlsx",
     rawData,
     keys
   },
   rawData = First@Import[ strURL <> strFileBaseName <> strDate <> strSuffix, "Data" ];
   keys = ( First @ rawData ) ;
   rawData // RightComposition[
     Rest,
     Map[ AssociationThread[ keys -> #] & ]
   ]
]; 

We now have each line of the tabular data in the form:

<| "dateRep" -> date, "day" -> day, "month" -> month, "year" -> year, "cases" -> *cases* ... |>

So each label in the table has become a Key of an Association and we now have a list of those. Such a data structure can be queried:

$data // RightComposition[
    Query[  
        Select[ #countriesAndTerritories == "Germany" &], 
        { "dateRep", "cases" } /* Values 
    ],
    TimeSeries,
    Accumulate
]; (* $data now is a time series of confirmed cases *)

DateListLogPlot[ casesGermany, PlotTheme -> "Detailed" ]

Cases Germany

EDIT

For those interested, there is a good post on Our World in Data about How do sources compare?. Wolfram Research seems to be using WHO data, but as explained in the link, there are good reasons to go for ECDC data.

I would like to expand upon Roman's suggestion to download data from the European Center for Disease Control (ECDC). The data will be stored in an Excel file at certain location with a filename, that includes the date. We can use that and build a list of associations from that.

$data = Module[
   {
     strDate = DateString[Today, "ISODate" ],
     strURL = "https://www.ecdc.europa.eu/sites/default/files/documents/",
     strFileBaseName = "COVID-19-geographic-disbtribution-worldwide-",
     strSuffix = ".xlsx",
     rawData,
     keys
   },
   rawData = First@Import[ strURL <> strFileBaseName <> strDate <> strSuffix, "Data" ];
   keys = ( First @ rawData ) ;
   rawData // RightComposition[
     Rest,
     Map[ AssociationThread[ keys -> #] & ]
   ]
]; 

We now have each line of the tabular data in the form:

<| "dateRep" -> date, "day" -> day, "month" -> month, "year" -> year, "cases" -> *cases* ... |>

So each label in the table has become a Key of an Association and we now have a list of those. Such a data structure can be queried:

$data // RightComposition[
    Query[  
        Select[ #countriesAndTerritories == "Germany" &], 
        { "dateRep", "cases" } /* Values 
    ],
    TimeSeries,
    Accumulate
]; (* $data now is a time series of confirmed cases *)

DateListLogPlot[ casesGermany, PlotTheme -> "Detailed" ]

Cases Germany

I would like to expand upon Roman's suggestion to download data from the European Center for Disease Control (ECDC). The data will be stored in an Excel file at certain location with a filename, that includes the date. We can use that and build a list of associations from that.

$data = Module[
   {
     strDate = DateString[Today, "ISODate" ],
     strURL = "https://www.ecdc.europa.eu/sites/default/files/documents/",
     strFileBaseName = "COVID-19-geographic-disbtribution-worldwide-",
     strSuffix = ".xlsx",
     rawData,
     keys
   },
   rawData = First@Import[ strURL <> strFileBaseName <> strDate <> strSuffix, "Data" ];
   keys = ( First @ rawData ) ;
   rawData // RightComposition[
     Rest,
     Map[ AssociationThread[ keys -> #] & ]
   ]
]; 

We now have each line of the tabular data in the form:

<| "dateRep" -> date, "day" -> day, "month" -> month, "year" -> year, "cases" -> *cases* ... |>

So each label in the table has become a Key of an Association and we now have a list of those. Such a data structure can be queried:

$data // RightComposition[
    Query[  
        Select[ #countriesAndTerritories == "Germany" &], 
        { "dateRep", "cases" } /* Values 
    ],
    TimeSeries,
    Accumulate
]; (* $data now is a time series of confirmed cases *)

DateListLogPlot[ casesGermany, PlotTheme -> "Detailed" ]

Cases Germany

EDIT

For those interested, there is a good post on Our World in Data about How do sources compare?. Wolfram Research seems to be using WHO data, but as explained in the link, there are good reasons to go for ECDC data.

corrected errors
Source Link
gwr
  • 13.6k
  • 2
  • 48
  • 82

I would like to expand upon Roman's suggestion to download data from the European Center for Disease Control (ECDC). The data will be stored in an Excel file at certain location with a filename, that includes the date. We can use that and build a list of associations from that.

$data = Module[
   {
     strDate = DateString[Today, "ISODate" ],
     strURL = "https://www.ecdc.europa.eu/sites/default/files/documents/",
     strFileBaseName = "COVID-19-geographic-disbtribution-worldwide-",
     strSuffix = ".xlsx",
     rawData,
     keys
   },
   rawData = First@Import[ strURL <> strFileBaseName <> strDate <> strSuffix, "Data" ];
   keys = ( First @ rawData ) ;
   rawData // RightComposition[
     Rest,
     Map[ AssociationThread[ keys -> #] & ]
   ]
]; 

We now have each line of the tabular data in the form:

<| "dateRep" -> date, "day" -> day, "month" -> month, "year" -> year, "cases" -> *cases* ... |>

So each label in the table has become a Key of an Association and we now have a list of those. Such a data structure can be queried:

$data // RightComposition[
    Query[  
        Select[ #countriesAndTerritories == "Germany" &], 
        { "dateRep", "cases" } /* Values 
    ],
    TimeSeries,
    Accumulate
]; (* $data now is a time series of confirmed cases *)

DateListLogPlot[ casesGermany, PlotTheme -> "Detailed" ]

Cases Germany

I would like to expand upon Roman's suggestion to download data from the European Center for Disease Control (ECDC). The data will be stored in an Excel file at certain location with a filename, that includes the date. We can use that and build a list of associations from that.

$data = Module[
   {
     strDate = DateString[Today, "ISODate" ],
     strURL = "https://www.ecdc.europa.eu/sites/default/files/documents/",
     strFileBaseName = "COVID-19-geographic-disbtribution-worldwide-",
     strSuffix = ".xlsx",
     rawData,
     keys
   },
   rawData = First@Import[ strFileBaseName <> strDate <> strSuffix, "Data" ];
   keys = ( First @ rawData ) ;
   rawData // RightComposition[
     Rest,
     Map[ AssociationThread[ keys -> #] & ]
   ]
]; 

We now have each line of the tabular data in the form:

<| "dateRep" -> date, "day" -> day, "month" -> month, "year" -> year, "cases" -> *cases* ... |>

So each label in the table has become a Key of an Association and we now have a list of those. Such a data structure can be queried:

$data // RightComposition[
    Query[  
        Select[ #countriesAndTerritories == "Germany" &], 
        { "dateRep", "cases" } /* Values 
    ],
    TimeSeries,
    Accumulate
]; (* $data now is a time series of confirmed cases *)

DateListLogPlot[ casesGermany, PlotTheme -> "Detailed" ]

Cases Germany

I would like to expand upon Roman's suggestion to download data from the European Center for Disease Control (ECDC). The data will be stored in an Excel file at certain location with a filename, that includes the date. We can use that and build a list of associations from that.

$data = Module[
   {
     strDate = DateString[Today, "ISODate" ],
     strURL = "https://www.ecdc.europa.eu/sites/default/files/documents/",
     strFileBaseName = "COVID-19-geographic-disbtribution-worldwide-",
     strSuffix = ".xlsx",
     rawData,
     keys
   },
   rawData = First@Import[ strURL <> strFileBaseName <> strDate <> strSuffix, "Data" ];
   keys = ( First @ rawData ) ;
   rawData // RightComposition[
     Rest,
     Map[ AssociationThread[ keys -> #] & ]
   ]
]; 

We now have each line of the tabular data in the form:

<| "dateRep" -> date, "day" -> day, "month" -> month, "year" -> year, "cases" -> *cases* ... |>

So each label in the table has become a Key of an Association and we now have a list of those. Such a data structure can be queried:

$data // RightComposition[
    Query[  
        Select[ #countriesAndTerritories == "Germany" &], 
        { "dateRep", "cases" } /* Values 
    ],
    TimeSeries,
    Accumulate
]; (* $data now is a time series of confirmed cases *)

DateListLogPlot[ casesGermany, PlotTheme -> "Detailed" ]

Cases Germany

Source Link
gwr
  • 13.6k
  • 2
  • 48
  • 82

I would like to expand upon Roman's suggestion to download data from the European Center for Disease Control (ECDC). The data will be stored in an Excel file at certain location with a filename, that includes the date. We can use that and build a list of associations from that.

$data = Module[
   {
     strDate = DateString[Today, "ISODate" ],
     strURL = "https://www.ecdc.europa.eu/sites/default/files/documents/",
     strFileBaseName = "COVID-19-geographic-disbtribution-worldwide-",
     strSuffix = ".xlsx",
     rawData,
     keys
   },
   rawData = First@Import[ strFileBaseName <> strDate <> strSuffix, "Data" ];
   keys = ( First @ rawData ) ;
   rawData // RightComposition[
     Rest,
     Map[ AssociationThread[ keys -> #] & ]
   ]
]; 

We now have each line of the tabular data in the form:

<| "dateRep" -> date, "day" -> day, "month" -> month, "year" -> year, "cases" -> *cases* ... |>

So each label in the table has become a Key of an Association and we now have a list of those. Such a data structure can be queried:

$data // RightComposition[
    Query[  
        Select[ #countriesAndTerritories == "Germany" &], 
        { "dateRep", "cases" } /* Values 
    ],
    TimeSeries,
    Accumulate
]; (* $data now is a time series of confirmed cases *)

DateListLogPlot[ casesGermany, PlotTheme -> "Detailed" ]

Cases Germany