# Functions for total Covid-19 cases and deaths in a US county

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

• Do you mean 'Country' or 'County'? For the US, county names are ambiguous, name of the state is needed to disambiguate. Jun 21, 2020 at 17:56

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"];


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: