4
$\begingroup$

Using something like what is in the link, I want to find a function that inputs county and outputs total Covid-19 cases in that county and, as a separate function, one that outputs total Covid-19 deaths in that county. TIA!

https://datarepository.wolframcloud.com/resources/Epidemic-Data-for-Novel-Coronavirus-COVID-19

$\endgroup$
  • $\begingroup$ Do you mean 'Country' or 'County'? For the US, county names are ambiguous, name of the state is needed to disambiguate. $\endgroup$ – Rohit Namjoshi Jun 21 at 17:56
9
$\begingroup$

Make sure you got the latest, and not running on old cache:

ResourceUpdate[ResourceObject["Epidemic Data for Novel Coronavirus COVID-19"]]

and get the data:

data=ResourceData["Epidemic Data for Novel Coronavirus COVID-19","USCounties"];
states=EntityList[EntityClass["AdministrativeDivision","AllUSStatesPlusDC"]];

I think something like this will do the job:

usaCountyCases[s_,c_]:=
data[Select[MatchQ[Interpreter["USState"][s],#State]&]][
Select[MatchQ[Interpreter["USCounty"][c<>" county, "<>s],#County]&]][
All,#ConfirmedCases["LastValue"]&]//Normal//First

usaCountyDeaths[s_,c_]:=
data[Select[MatchQ[Interpreter["USState"][s],#State]&]][
Select[MatchQ[Interpreter["USCounty"][c<>" county, "<>s],#County]&]][
All,#Deaths["LastValue"]&]//Normal//First

Note another way of writing this functions is for instance:

usaCountyCases[s_,c_]:=
data[
    Select[
        MatchQ[Interpreter["USState"][s],#State]&&
        MatchQ[Interpreter["USCounty"][c<>" county, "<>s],#County]&]][
All,#ConfirmedCases["LastValue"]&]//Normal//First

Usage case:

In[]:= usaCountyCases["fl","pinellas"]
Out[]= 3438

In[]:= usaCountyDeaths["fl","pinellas"]
Out[]= 114

which at this moment gives the same as for instance Google:

https://www.google.com/search?q=covid-19+cases+in+pinellas+county+fl

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ It isn't working, although it looks perfect. Are any of those commands strictly version 12? I have version 11.1. Is that why these aren't running? $\endgroup$ – Veritas Lux Jun 22 at 2:07
  • $\begingroup$ My version is 12.1.1. and does work in that version :-) You can see if some commands are not available in your version by them being blue instead oof black. Also you can simply check if the functions are in your docs. Make sure you got all the data properly before running the functions. $\endgroup$ – Vitaliy Kaurov Jun 22 at 3:14
  • $\begingroup$ I tried it in a higher version and it works. What I ultimately want to do is find the correlation between county population density versus county covid-19 cases. I just set it up and am running trial code. In cases with a small number of counties, 5 counties take 20 seconds to get the correlation, so just imagine 3109 counties. I hope it will be done in 3-4 hours. Is this long crunch time to be expected? $\endgroup$ – Veritas Lux Jun 22 at 17:14
  • $\begingroup$ @VeritasLux this is a different question, you might want to ask it as a separate question. The way data accessed, and hence speeds, in these 2 cases might be different. $\endgroup$ – Vitaliy Kaurov Jun 22 at 17:30

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.