diff --git a/module3/exo3/exercice_fr.ipynb b/module3/exo3/exercice_fr.ipynb index 0bbbe371b01e359e381e43239412d77bf53fb1fb..c95672f65c2a5c63e53c0797383f8434e9d2d67f 100644 --- a/module3/exo3/exercice_fr.ipynb +++ b/module3/exo3/exercice_fr.ipynb @@ -1,5 +1,96 @@ { - "cells": [], + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# Télécharger les données\n", + "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 = pd.read_csv(url)\n", + "\n", + "# Exclure Hong Kong des données de la Chine\n", + "data_ex_china = data[~((data['Country/Region'] == 'China') & (data['Province/State'] == 'Hong Kong SAR'))]\n", + "\n", + "# Filtrer les territoires d'outre-mer pour la France et le Royaume-Uni\n", + "france_excl = ['French Guiana', 'Guadeloupe', 'Martinique', 'Mayotte', 'Reunion', 'Saint Barthelemy', 'Saint Pierre and Miquelon']\n", + "uk_excl = ['Anguilla', 'Bermuda', 'British Virgin Islands', 'Cayman Islands', 'Channel Islands', 'Falkland Islands (Malvinas)', 'Gibraltar', 'Isle of Man', 'Montserrat', 'Saint Helena', 'Turks and Caicos Islands']\n", + "\n", + "# Filtrer les données pour exclure ces territoires\n", + "data_ex_terri = data_ex_china[\n", + " ~((data_ex_china['Country/Region'] == 'France') & (data_ex_china['Province/State'].isin(france_excl))) &\n", + " ~((data_ex_china['Country/Region'] == 'United Kingdom') & (data_ex_china['Province/State'].isin(uk_excl)))\n", + "]\n", + "\n", + "# Filtrer les données pour les pays d'intérêt (en excluant les territoires)\n", + "countries = [\n", + " \"Belgium\", \"China\", \"France\", \"Germany\", \"Iran\", \"Italy\", \"Japan\",\n", + " \"Korea, South\", \"Netherlands\", \"Portugal\", \"Spain\", \"United Kingdom\", \"US\", \"Hong Kong SAR\"\n", + "]\n", + "\n", + "data_filtered = data_ex_terri[data_ex_terri['Country/Region'].isin(countries)]\n", + "\n", + "# Agréger les données par pays (somme des provinces)\n", + "data_grouped = data_filtered.groupby(\"Country/Region\").sum().reset_index()\n", + "\n", + "# Supprimer les colonnes non nécessaires\n", + "data_grouped = data_grouped.drop(columns=[\"Lat\", \"Long\"])\n", + "\n", + "# Transposer les données pour avoir les dates en lignes\n", + "data_transposed = data_grouped.set_index(\"Country/Region\").T\n", + "\n", + "# Tracer les graphiques\n", + "plt.figure(figsize=(14, 8))\n", + "\n", + "# Graphique à échelle linéaire\n", + "plt.subplot(2, 1, 1)\n", + "for country in countries:\n", + " if country in data_transposed.columns:\n", + " plt.plot(data_transposed.index, data_transposed[country], label=country)\n", + "plt.title('Nombre cumulé de cas de COVID-19 (Échelle linéaire)')\n", + "plt.xlabel('Date')\n", + "plt.ylabel('Nombre cumulé de cas')\n", + "plt.legend()\n", + "plt.xticks(rotation=90)\n", + "\n", + "# Graphique à échelle logarithmique\n", + "plt.subplot(2, 1, 2)\n", + "for country in countries:\n", + " if country in data_transposed.columns:\n", + " plt.plot(data_transposed.index, data_transposed[country], label=country)\n", + "plt.yscale('log')\n", + "plt.title('Nombre cumulé de cas de COVID-19 (Échelle logarithmique)')\n", + "plt.xlabel('Date')\n", + "plt.ylabel('Nombre cumulé de cas (échelle logarithmique)')\n", + "plt.legend()\n", + "plt.xticks(rotation=90)\n", + "\n", + "plt.tight_layout()\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], "metadata": { "kernelspec": { "display_name": "Python 3", @@ -16,10 +107,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.3" + "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 } -