Skip to content

Instantly share code, notes, and snippets.

@gilesdring
Created March 11, 2020 09:36
Show Gist options
  • Select an option

  • Save gilesdring/62053ed44f7d75ea3f9041ab0c020e7e to your computer and use it in GitHub Desktop.

Select an option

Save gilesdring/62053ed44f7d75ea3f9041ab0c020e7e to your computer and use it in GitHub Desktop.
covid-19-cases-uk.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "covid-19-cases-uk.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyNQoFMlP0mwAqi3cTJG7FCM",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/gilesdring/62053ed44f7d75ea3f9041ab0c020e7e/covid-19-cases-uk.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Ttkt9oiF7p22",
"colab_type": "text"
},
"source": [
"# COVID-19 cases in UK\n",
"\n",
"This notebook presents the data that has been publicly shared via the ArcGIS visualisation of the spread of COVID-19 cases in the UK.\n",
"\n",
"https://www.gov.uk/government/publications/covid-19-track-coronavirus-cases\n",
"\n",
"Currently the dashboard only links to aggregated cases per day, with no geographical breakdown.\n",
"\n",
"To see the graph and update the figures, click on open in Colab, then select Run All from the Runtime menu. Alternatively press CTRL-F9 (Command-F9 on Mac)"
]
},
{
"cell_type": "code",
"metadata": {
"id": "ThewHhA52LZp",
"colab_type": "code",
"colab": {}
},
"source": [
"import pandas as pd\n",
"import plotly.graph_objects as go"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "1q2esJl_168Y",
"colab_type": "code",
"colab": {}
},
"source": [
"daily_indicators = 'https://www.arcgis.com/sharing/rest/content/items/bc8ee90225644ef7a6f4dd1b13ea1d67/data'\n",
"daily_cases = 'https://www.arcgis.com/sharing/rest/content/items/e5fd11150d274bebaaf8fe2a7a2bda11/data'"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "DBR55W562PFU",
"colab_type": "code",
"colab": {}
},
"source": [
"c = pd.read_excel(daily_cases)\n",
"i = pd.read_excel(daily_indicators)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "5tcMcGKE3a1R",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 542
},
"outputId": "cef7def2-6cdc-4736-c652-d7971103793e"
},
"source": [
"fig = go.Figure([\n",
" go.Scatter(x=c.DateVal, y=c.CMODateCount, name='New cases'),\n",
" go.Scatter(x=c.DateVal, y=c.CumCases, name='Cumulative cases')\n",
" ],\n",
" layout_title_text=\"COVID-19 cases per day\")\n",
"fig.show()"
],
"execution_count": 31,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"<html>\n",
"<head><meta charset=\"utf-8\" /></head>\n",
"<body>\n",
" <div>\n",
" <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script>\n",
" <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
" <script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script> \n",
" <div id=\"2e419119-200d-4d77-a8cb-a18d1dce305e\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>\n",
" <script type=\"text/javascript\">\n",
" \n",
" window.PLOTLYENV=window.PLOTLYENV || {};\n",
" \n",
" if (document.getElementById(\"2e419119-200d-4d77-a8cb-a18d1dce305e\")) {\n",
" Plotly.newPlot(\n",
" '2e419119-200d-4d77-a8cb-a18d1dce305e',\n",
" [{\"name\": \"New cases\", \"type\": \"scatter\", \"x\": [\"2020-01-31T00:00:00\", \"2020-02-01T00:00:00\", \"2020-02-02T00:00:00\", \"2020-02-03T00:00:00\", \"2020-02-04T00:00:00\", \"2020-02-05T00:00:00\", \"2020-02-06T00:00:00\", \"2020-02-07T00:00:00\", \"2020-02-08T00:00:00\", \"2020-02-09T00:00:00\", \"2020-02-10T00:00:00\", \"2020-02-11T00:00:00\", \"2020-02-12T00:00:00\", \"2020-02-13T00:00:00\", \"2020-02-14T00:00:00\", \"2020-02-15T00:00:00\", \"2020-02-16T00:00:00\", \"2020-02-17T00:00:00\", \"2020-02-18T00:00:00\", \"2020-02-19T00:00:00\", \"2020-02-20T00:00:00\", \"2020-02-21T00:00:00\", \"2020-02-22T00:00:00\", \"2020-02-23T00:00:00\", \"2020-02-24T00:00:00\", \"2020-02-25T00:00:00\", \"2020-02-26T00:00:00\", \"2020-02-27T00:00:00\", \"2020-02-28T00:00:00\", \"2020-02-29T00:00:00\", \"2020-03-01T00:00:00\", \"2020-03-02T00:00:00\", \"2020-03-03T00:00:00\", \"2020-03-04T00:00:00\", \"2020-03-05T00:00:00\", \"2020-03-06T00:00:00\", \"2020-03-07T00:00:00\", \"2020-03-08T00:00:00\", \"2020-03-09T00:00:00\", \"2020-03-10T00:00:00\"], \"y\": [2, 0, 0, 0, 0, 0, 1, 0, 0, 1, 4, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 6, 4, 12, 5, 11, 34, 29, 46, 46, 65, 50, 52]}, {\"name\": \"Cumulative cases\", \"type\": \"scatter\", \"x\": [\"2020-01-31T00:00:00\", \"2020-02-01T00:00:00\", \"2020-02-02T00:00:00\", \"2020-02-03T00:00:00\", \"2020-02-04T00:00:00\", \"2020-02-05T00:00:00\", \"2020-02-06T00:00:00\", \"2020-02-07T00:00:00\", \"2020-02-08T00:00:00\", \"2020-02-09T00:00:00\", \"2020-02-10T00:00:00\", \"2020-02-11T00:00:00\", \"2020-02-12T00:00:00\", \"2020-02-13T00:00:00\", \"2020-02-14T00:00:00\", \"2020-02-15T00:00:00\", \"2020-02-16T00:00:00\", \"2020-02-17T00:00:00\", \"2020-02-18T00:00:00\", \"2020-02-19T00:00:00\", \"2020-02-20T00:00:00\", \"2020-02-21T00:00:00\", \"2020-02-22T00:00:00\", \"2020-02-23T00:00:00\", \"2020-02-24T00:00:00\", \"2020-02-25T00:00:00\", \"2020-02-26T00:00:00\", \"2020-02-27T00:00:00\", \"2020-02-28T00:00:00\", \"2020-02-29T00:00:00\", \"2020-03-01T00:00:00\", \"2020-03-02T00:00:00\", \"2020-03-03T00:00:00\", \"2020-03-04T00:00:00\", \"2020-03-05T00:00:00\", \"2020-03-06T00:00:00\", \"2020-03-07T00:00:00\", \"2020-03-08T00:00:00\", \"2020-03-09T00:00:00\", \"2020-03-10T00:00:00\"], \"y\": [2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 13, 13, 13, 13, 19, 23, 35, 40, 51, 85, 114, 160, 206, 271, 321, 373]}],\n",
" {\"template\": {\"data\": {\"bar\": [{\"error_x\": {\"color\": \"#2a3f5f\"}, \"error_y\": {\"color\": \"#2a3f5f\"}, \"marker\": {\"line\": {\"color\": \"#E5ECF6\", \"width\": 0.5}}, \"type\": \"bar\"}], \"barpolar\": [{\"marker\": {\"line\": {\"color\": \"#E5ECF6\", \"width\": 0.5}}, \"type\": \"barpolar\"}], \"carpet\": [{\"aaxis\": {\"endlinecolor\": \"#2a3f5f\", \"gridcolor\": \"white\", \"linecolor\": \"white\", \"minorgridcolor\": \"white\", \"startlinecolor\": \"#2a3f5f\"}, \"baxis\": {\"endlinecolor\": \"#2a3f5f\", \"gridcolor\": \"white\", \"linecolor\": \"white\", \"minorgridcolor\": \"white\", \"startlinecolor\": \"#2a3f5f\"}, \"type\": \"carpet\"}], \"choropleth\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"type\": \"choropleth\"}], \"contour\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"contour\"}], \"contourcarpet\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"type\": \"contourcarpet\"}], \"heatmap\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"heatmap\"}], \"heatmapgl\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"heatmapgl\"}], \"histogram\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"histogram\"}], \"histogram2d\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"histogram2d\"}], \"histogram2dcontour\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"histogram2dcontour\"}], \"mesh3d\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"type\": \"mesh3d\"}], \"parcoords\": [{\"line\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"parcoords\"}], \"pie\": [{\"automargin\": true, \"type\": \"pie\"}], \"scatter\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scatter\"}], \"scatter3d\": [{\"line\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scatter3d\"}], \"scattercarpet\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scattercarpet\"}], \"scattergeo\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scattergeo\"}], \"scattergl\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scattergl\"}], \"scattermapbox\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scattermapbox\"}], \"scatterpolar\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scatterpolar\"}], \"scatterpolargl\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scatterpolargl\"}], \"scatterternary\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scatterternary\"}], \"surface\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"surface\"}], \"table\": [{\"cells\": {\"fill\": {\"color\": \"#EBF0F8\"}, \"line\": {\"color\": \"white\"}}, \"header\": {\"fill\": {\"color\": \"#C8D4E3\"}, \"line\": {\"color\": \"white\"}}, \"type\": \"table\"}]}, \"layout\": {\"annotationdefaults\": {\"arrowcolor\": \"#2a3f5f\", \"arrowhead\": 0, \"arrowwidth\": 1}, \"coloraxis\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"colorscale\": {\"diverging\": [[0, \"#8e0152\"], [0.1, \"#c51b7d\"], [0.2, \"#de77ae\"], [0.3, \"#f1b6da\"], [0.4, \"#fde0ef\"], [0.5, \"#f7f7f7\"], [0.6, \"#e6f5d0\"], [0.7, \"#b8e186\"], [0.8, \"#7fbc41\"], [0.9, \"#4d9221\"], [1, \"#276419\"]], \"sequential\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"sequentialminus\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]]}, \"colorway\": [\"#636efa\", \"#EF553B\", \"#00cc96\", \"#ab63fa\", \"#FFA15A\", \"#19d3f3\", \"#FF6692\", \"#B6E880\", \"#FF97FF\", \"#FECB52\"], \"font\": {\"color\": \"#2a3f5f\"}, \"geo\": {\"bgcolor\": \"white\", \"lakecolor\": \"white\", \"landcolor\": \"#E5ECF6\", \"showlakes\": true, \"showland\": true, \"subunitcolor\": \"white\"}, \"hoverlabel\": {\"align\": \"left\"}, \"hovermode\": \"closest\", \"mapbox\": {\"style\": \"light\"}, \"paper_bgcolor\": \"white\", \"plot_bgcolor\": \"#E5ECF6\", \"polar\": {\"angularaxis\": {\"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\"}, \"bgcolor\": \"#E5ECF6\", \"radialaxis\": {\"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\"}}, \"scene\": {\"xaxis\": {\"backgroundcolor\": \"#E5ECF6\", \"gridcolor\": \"white\", \"gridwidth\": 2, \"linecolor\": \"white\", \"showbackground\": true, \"ticks\": \"\", \"zerolinecolor\": \"white\"}, \"yaxis\": {\"backgroundcolor\": \"#E5ECF6\", \"gridcolor\": \"white\", \"gridwidth\": 2, \"linecolor\": \"white\", \"showbackground\": true, \"ticks\": \"\", \"zerolinecolor\": \"white\"}, \"zaxis\": {\"backgroundcolor\": \"#E5ECF6\", \"gridcolor\": \"white\", \"gridwidth\": 2, \"linecolor\": \"white\", \"showbackground\": true, \"ticks\": \"\", \"zerolinecolor\": \"white\"}}, \"shapedefaults\": {\"line\": {\"color\": \"#2a3f5f\"}}, \"ternary\": {\"aaxis\": {\"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\"}, \"baxis\": {\"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\"}, \"bgcolor\": \"#E5ECF6\", \"caxis\": {\"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\"}}, \"title\": {\"x\": 0.05}, \"xaxis\": {\"automargin\": true, \"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\", \"title\": {\"standoff\": 15}, \"zerolinecolor\": \"white\", \"zerolinewidth\": 2}, \"yaxis\": {\"automargin\": true, \"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\", \"title\": {\"standoff\": 15}, \"zerolinecolor\": \"white\", \"zerolinewidth\": 2}}}, \"title\": {\"text\": \"COVID-19 cases per day\"}},\n",
" {\"responsive\": true}\n",
" ).then(function(){\n",
" \n",
"var gd = document.getElementById('2e419119-200d-4d77-a8cb-a18d1dce305e');\n",
"var x = new MutationObserver(function (mutations, observer) {{\n",
" var display = window.getComputedStyle(gd).display;\n",
" if (!display || display === 'none') {{\n",
" console.log([gd, 'removed!']);\n",
" Plotly.purge(gd);\n",
" observer.disconnect();\n",
" }}\n",
"}});\n",
"\n",
"// Listen for the removal of the full notebook cells\n",
"var notebookContainer = gd.closest('#notebook-container');\n",
"if (notebookContainer) {{\n",
" x.observe(notebookContainer, {childList: true});\n",
"}}\n",
"\n",
"// Listen for the clearing of the current output cell\n",
"var outputEl = gd.closest('.output');\n",
"if (outputEl) {{\n",
" x.observe(outputEl, {childList: true});\n",
"}}\n",
"\n",
" })\n",
" };\n",
" \n",
" </script>\n",
" </div>\n",
"</body>\n",
"</html>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "zkNj_qi64N-F",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 81
},
"outputId": "8356c11b-b7cc-406a-f302-51aaff09dde1"
},
"source": [
"i"
],
"execution_count": 33,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>DateVal</th>\n",
" <th>TotalUKCases</th>\n",
" <th>NewUKCases</th>\n",
" <th>TotalUKDeaths</th>\n",
" <th>EnglandCases</th>\n",
" <th>ScotlandCases</th>\n",
" <th>WalesCases</th>\n",
" <th>NICases</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2020-03-10</td>\n",
" <td>373</td>\n",
" <td>52</td>\n",
" <td>6</td>\n",
" <td>324</td>\n",
" <td>27</td>\n",
" <td>6</td>\n",
" <td>16</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" DateVal TotalUKCases NewUKCases ... ScotlandCases WalesCases NICases\n",
"0 2020-03-10 373 52 ... 27 6 16\n",
"\n",
"[1 rows x 8 columns]"
]
},
"metadata": {
"tags": []
},
"execution_count": 33
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment