Covid19

parent a54d8563
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Subject 7: The SARS-CoV-2 (Covid-19) epidemic"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The data on the SARS-CoV-2 (Covid-19) epidemic are available on [Github](https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv). The file is in CSV format, each line corresponds to a day in the observation period"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import urllib.request\n",
"\n",
"data_url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv'\n",
"data_file = \"time_series_covid19_confirmed_global.csv\"\n",
"\n",
"if not os.path.exists(data_file):\n",
" urllib.request.urlretrieve(data_url, data_file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"raw_data = pd.read_csv(data_file)\n",
"raw_data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Show Country/Region available in dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"raw_data['Country/Region']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Take value of _**Belgium**_ :"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"belgium_raw = raw_data[raw_data['Country/Region'].str.contains('Belgium')]\n",
"print(belgium_raw)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Only take cumulative cases data with date"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"belgium_cases = belgium_raw.iloc[:, 4:]\n",
"belgium_cases"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"PLot cumulative number of cases each day:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ax = plt.gca()\n",
"ax.get_xaxis().set_visible(False)\n",
"plt.plot(belgium_cases.T)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Take value of _**China**_ :"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"china_raw = raw_data[raw_data['Country/Region'].str.contains('China')]\n",
"print(china_raw)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Calculate total cumulative cases in all china:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"china_cases = china_raw.iloc[:, 4:].sum(axis=0).to_frame().T\n",
"china_cases"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"PLot cumulative number of cases each day:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ax = plt.gca()\n",
"ax.get_xaxis().set_visible(False)\n",
"plt.plot(china_cases.T)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Take value of _**France**_ :"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"france_raw = raw_data[raw_data['Country/Region'].str.contains('France')]\n",
"# print(france_raw)\n",
"france_cases = france_raw.iloc[:, 4:].sum(axis=0).to_frame().T\n",
"# france_cases\n",
"# ax = plt.gca()\n",
"# ax.get_xaxis().set_visible(False)\n",
"# plt.plot(france_cases.T)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Take value of _**Germany**_ :"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"germany_raw = raw_data[raw_data['Country/Region'].str.contains('Germany')]\n",
"# print(germany_raw)\n",
"germany_cases = germany_raw.iloc[:, 4:]\n",
"# germany_cases\n",
"# ax = plt.gca()\n",
"# ax.get_xaxis().set_visible(False)\n",
"# plt.plot(germany_cases.T)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Take value of _**Italy**_ :"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"italy_raw = raw_data[raw_data['Country/Region'].str.contains('Italy')]\n",
"italy_cases = italy_raw.iloc[:, 4:]\n",
"# italy_cases\n",
"# ax = plt.gca()\n",
"# ax.get_xaxis().set_visible(False)\n",
"# plt.plot(italy_cases.T)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Take value of _**Japan**_ :"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"japan_raw = raw_data[raw_data['Country/Region'].str.contains('Japan')]\n",
"japan_cases = japan_raw.iloc[:, 4:]\n",
"# japan_cases\n",
"# ax = plt.gca()\n",
"# ax.get_xaxis().set_visible(False)\n",
"# plt.plot(japan_cases.T)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# ax = plt.gca()\n",
"# ax.get_xaxis().set_visible(False)\n",
"\n",
"# plt.plot(belgium_cases.T, label='Belgium')\n",
"# plt.plot(china_cases.T, label='China')\n",
"# plt.plot(france_cases.T, label='France')\n",
"\n",
"# # Add labels and legend\n",
"# plt.ylabel('Cumulative cases')\n",
"# plt.legend()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Take value of _**Netherlands**_ :"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"netherlands_raw = raw_data[raw_data['Country/Region'].str.contains('Netherlands')]\n",
"netherlands_cases = netherlands_raw.iloc[:, 4:].sum(axis=0).to_frame().T\n",
"# netherlands_cases\n",
"# ax = plt.gca()\n",
"# ax.get_xaxis().set_visible(False)\n",
"# plt.plot(netherlands_cases.T)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Take value of _**Spain**_ :"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"spain_raw = raw_data[raw_data['Country/Region'].str.contains('Spain')]\n",
"spain_cases = spain_raw.iloc[:, 4:]\n",
"# spain_cases\n",
"# ax = plt.gca()\n",
"# ax.get_xaxis().set_visible(False)\n",
"# plt.plot(spain_cases.T)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Take value of _**United Kingdom**_ :"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"UK_raw = raw_data[raw_data['Country/Region'].str.contains('United Kingdom')]\n",
"UK_cases = UK_raw.iloc[:, 4:].sum(axis=0).to_frame().T\n",
"# UK_cases\n",
"# ax = plt.gca()\n",
"# ax.get_xaxis().set_visible(False)\n",
"# plt.plot(UK_cases.T)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'netherlands_cases' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-16-924bdc3c384f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitaly_cases\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mT\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'Italy'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mjapan_cases\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mT\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'Japan'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 10\u001b[0;31m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnetherlands_cases\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mT\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'Netherlands'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 11\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mspain_cases\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mT\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'Spain'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mUK_cases\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mT\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'United Kingdom'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'netherlands_cases' is not defined"
]
}
],
"source": [
"ax = plt.gca()\n",
"ax.get_xaxis().set_visible(False)\n",
"\n",
"plt.plot(belgium_cases.T, label='Belgium')\n",
"plt.plot(china_cases.T, label='China')\n",
"plt.plot(france_cases.T, label='France')\n",
"plt.plot(germany_cases.T, label='Germany')\n",
"plt.plot(italy_cases.T, label='Italy')\n",
"plt.plot(japan_cases.T, label='Japan')\n",
"plt.plot(netherlands_cases.T, label='Netherlands')\n",
"plt.plot(spain_cases.T, label='Spain')\n",
"plt.plot(UK_cases.T, label='United Kingdom')\n",
"\n",
"# Add labels and legend\n",
"plt.ylabel('Cumulative cases')\n",
"plt.legend()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment