COVID-19 - Ireland County Data
Introduction
The Irish government has made available several datasets relating to the COVID-19 pandemic. These are available at the Ireland’s COVID-19 Data Hub.
This example looks at how you can download and produce visualisations of the County Statistics datasets (Covid19CountyStatisticsHPSCIreland) using a Python script.
Libraries
The following libraries are used in the script:
- argparse - makes it easy to write user-friendly command-line interfaces buy handling command line parameters.
- requests - allows sending HTTP requests through Python, which will be used to obtain the dataset from the internet.
- pandas - open-source Python library that provides powerful data structures and data analysis tools to deal with datasets.
- matplotlib.pyplot - used for data visualisation.
- matplotlib.dates - used for date formatting on data visualisations.
Command Line Arguments
The scripts takes two parameters:
- county - the name of the county you want to plot data for
- days - the number of days data you want to plot
Get Dataset
The CSV version of the dataset is downloaded to the local file system.
Filter Dataset
The CSV file is loaded into a pandas DataFrame and filtered by county name and the number of days to plot.
Format Date
When loaded into the dataframe the TimeStamp is a string, convert it into a datetime object for charting and formatting.
Bar Chart - Cumulative Confirmed Cases By County
The cumulative confirmed cases are plotted using the TimeStamp and ConfirmedCovidCases fields in the DataFrame.
Bar Chart - New Confirmed Cases By County
The new daily confirmed cases are plotted using the TimeStamp and the diff method on ConfirmedCovidCases. The diff method calculates the difference of a DataFrame element compared with another element in the DataFrame (default is element in previous row).
Usage
Help for parameters can be viewed by:
This is an example of the command to plot the previous 30 days of data for county Dublin:
Conclusion
This is just one example of what can be done with the datasets available from the Ireland’s COVID-19 Data Hub.
Full code for this example available on GitHub here.