Wolfram makes the COVID-19 case data available in a form that is conveniently formatted for processing in Mathematica.

It can be accessed using:

data2 = ResourceData[ResourceUpdate["Epidemic Data for Novel Coronavirus COVID-19"]]

[Syntax provided by swish in his answer to COVID-19 Wolfram Data Repository Retrieval ]

enter image description here

Suppose I want to pull out the data for New York state. Since NY state is in the third row, I can get it using:


However, NY state might not always be in the third row. So how would I instead extract that row by how it is named in the AdministrativeDivision column ("New York, United States")?

  • 1
    $\begingroup$ data2[Select[#AdministrativeDivision == {"New York", "United States"} &]? $\endgroup$
    – kglr
    Apr 5, 2020 at 5:44
  • 1
    $\begingroup$ ... or Query[Select[#a == {"New York", "United States"} &]] @data2? $\endgroup$
    – kglr
    Apr 5, 2020 at 5:47
  • 1
    $\begingroup$ Not knowing the full administrative division names, I tend to use StringMatchQ on the county names. Not very pretty, and somewhat embarrassing (to me), but it works. $\endgroup$ Apr 5, 2020 at 15:03
  • $\begingroup$ @kglr Yeah, something along those lines was what I had been trying, and none of my attempts worked. Unfortunately, none of yours do either ;). The first one (after adding the missing bracket at the end) gives an empty output, and the second one gives a Failure message. What's needed is the construction provided by LouisB: data2[Select[#AdministrativeDivision == Entity["AdministrativeDivision", {"NewYork", "UnitedStates"}] &]]. I've found Wolfram's Entity syntax to be among the most cumbersome and non-intuitive within the Wolfram Language. $\endgroup$
    – theorist
    Apr 5, 2020 at 18:49
  • 1
    $\begingroup$ You could also try something like data[Select[! MissingQ[#AdministrativeDivision] && ContainsAny[ CanonicalName@#AdministrativeDivision, {"NewYork"}] &]] $\endgroup$
    – chuy
    Apr 6, 2020 at 19:58

1 Answer 1


Here's the code I've been using for various states:

res = ResourceData["Epidemic Data for Novel Coronavirus COVID-19"];

cal = Entity[
    {"California", "UnitedStates"}];
ny = Entity["AdministrativeDivision",
    {"NewYork", "UnitedStates"}];

state = ny;

data = res[Select[#AdministrativeDivision == state &]][[1, -3 ;;]] // 

ts = data[[#]] & /@ {"ConfirmedCases", "RecoveredCases", "Deaths"};

DateListPlot[ts, PlotRange -> {All, All},
 Frame -> True, PlotLabel -> state["Name"],
 GridLines -> Automatic]

To sum the data over many administrative divisions I've been using this:

china = Entity["Country", "China"];
With[{data = 
   res[Select[(#Country == china &&
        Not[Head[#AdministrativeDivision] === Missing]) &]]},
 GraphicsColumn[DateListPlot[data[All, #] // Total,
     PlotRange -> {All, All}, GridLines -> True] & /@ 
   {"ConfirmedCases", "RecoveredCases", "Deaths"}]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.