Wolfram Research

Function Repository Resource:

NYTimesCOVID19Data

Source Notebook

Import data from the New York Times COVID-19 United States County-by-County data

Contributed by: Bob Sandheinrich and Jesse Friedman

ResourceFunction["NYTimesCOVID19Data"][type]

retrieve the specified data type from the New York Times Github repository.

Details and Options

Available types are "USCounties" and "USCountiesTimeSeries".
ResourceFunction["NYTimesCOVID19Data"][] gives “USCounties” data.
Every evaluation of NYTimesCOVID19Data retrieves fresh data from the web. It is not useful to call this function more frequently than the data is updated by the New York Times. Instead store it as a variable or use Once to avoid repeated downloads.

Examples

Basic Examples

Retrieve the formatted dataset:

In[1]:=
AbsoluteTiming[data = ResourceFunction["NYTimesCOVID19Data"][];]
Out[1]=

Get the twenty entries with the most deaths:

In[2]:=
TakeLargestBy[data, "Deaths", 20]
Out[2]=

Show each county only once:

In[3]:=
data[Reverse /* DeleteDuplicatesBy[#County &] /* TakeLargestBy["Deaths", 20]]
Out[3]=

Get time series data for each state:

In[4]:=
timeseries = ResourceFunction["NYTimesCOVID19Data"]["USCountiesTimeSeries"];
In[5]:=
timeseries[[1 ;; 5]]
Out[5]=

Plot the number of deaths over time for the ten counties with the most deaths:

In[6]:=
DateListPlot[
 timeseries[TakeLargestBy[#Deaths["LastValue"] &, 10], "Deaths"], PlotRange -> Full]
Out[6]=

Plot the number of cases:

In[7]:=
DateListPlot[
 timeseries[TakeLargestBy[#Cases["LastValue"] &, 10], "Cases"], PlotRange -> Full]
Out[7]=

Scope

Create a map of case density in each county:

In[8]:=
countyLatestCaseCounts = ResourceFunction["NYTimesCOVID19Data"]["USCountiesTimeSeries"][
   All, #Cases["LastValue"] &];
In[9]:=
GeoHistogram[
 Normal@countyLatestCaseCounts[Select[IntegerQ]],
 100,
 PlotLegends -> Automatic,
 GeoRange -> Entity["Country", "UnitedStates"]
 ]
Out[9]=

Filter out cases from only New York state:

In[10]:=
nyCountyCases = ResourceFunction["NYTimesCOVID19Data"]["USCountiesTimeSeries"][
   Select[#State === Entity["AdministrativeDivision", {"NewYork", "UnitedStates"}] &], "Cases"];
In[11]:=
DateListLogPlot[
 nyCountyCases[
  KeyMap[StringTrim[First@StringSplit[CommonName@#, ","], " County"] &]],
 Sequence[
 PlotRange -> All, PlotLegends -> Automatic, PlotLabel -> "COVID-19 cases in New York by county"]
 ]
Out[11]=

Resource History

Source Metadata

Related Resources

License Information