Add check data file in local folder, otherwise download a new version from URL

parent 8e889d4e
......@@ -58,11 +58,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lecture des données\n",
"## Source des données\n",
"\n",
"Les données de l'incidence du syndrome grippal sont disponibles du site Web du [Réseau Sentinelles](http://www.sentiweb.fr/). Nous les récupérons sous forme d'un fichier **en format CSV** dont chaque ligne correspond à une semaine de la période demandée. Nous téléchargeons toujours le jeu de données complet, qui **commence en 1984** et se termine avec une semaine récente."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Approche directe _via_ URL :"
]
},
{
"cell_type": "code",
"execution_count": 3,
......@@ -72,6 +79,41 @@
"data_url = \"http://www.sentiweb.fr/datasets/incidence-PAY-3.csv\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Approche préférée, se prémunie d'un URL déplacé ou un fichier de format modifié."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Le fichier 'incidence-PAY-3.csv' existe déjà en local.\n"
]
}
],
"source": [
"import os\n",
"import urllib.request\n",
"\n",
"nom_fichier = \"incidence-PAY-3.csv\"\n",
"\n",
"if os.path.exists(nom_fichier):\n",
" print(f\"Le fichier '{nom_fichier}' existe déjà en local.\")\n",
" data_url = nom_fichier\n",
"else:\n",
" print(f\"Fichier non trouvé, téléchargement en cours...\")\n",
" urllib.request.urlretrieve(data_url, nom_fichier)\n",
" print(f\"Téléchargement terminé : '{nom_fichier}'\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -94,9 +136,16 @@
"La première ligne du fichier CSV est un commentaire, que nous ignorons en précisant `skiprows=1`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lecture des données"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"metadata": {},
"outputs": [
{
......@@ -293,7 +342,7 @@
"2178 213.0 FR France "
]
},
"execution_count": 4,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
......@@ -315,7 +364,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 8,
"metadata": {},
"outputs": [
{
......@@ -377,7 +426,7 @@
"1942 FR France "
]
},
"execution_count": 5,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
......@@ -395,7 +444,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 9,
"metadata": {},
"outputs": [
{
......@@ -433,7 +482,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 10,
"metadata": {},
"outputs": [
{
......@@ -561,7 +610,7 @@
"4 FR France 2026-06-29/2026-07-05 "
]
},
"execution_count": 7,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
......@@ -597,7 +646,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 11,
"metadata": {},
"outputs": [
{
......@@ -734,7 +783,7 @@
"1984-11-26/1984-12-02 110.0 176.0 FR France "
]
},
"execution_count": 8,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
......@@ -763,7 +812,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 12,
"metadata": {},
"outputs": [
{
......@@ -795,7 +844,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 13,
"metadata": {},
"outputs": [
{
......@@ -831,7 +880,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 14,
"metadata": {},
"outputs": [
{
......@@ -888,7 +937,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 15,
"metadata": {},
"outputs": [
{
......@@ -901,7 +950,7 @@
" Period('1989-07-31/1989-08-06', 'W-SUN')]"
]
},
"execution_count": 12,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
......@@ -924,7 +973,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 16,
"metadata": {},
"outputs": [
{
......@@ -938,7 +987,7 @@
"dtype: int64"
]
},
"execution_count": 13,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
......@@ -968,7 +1017,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 17,
"metadata": {},
"outputs": [
{
......@@ -1001,7 +1050,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 18,
"metadata": {},
"outputs": [
{
......@@ -1013,7 +1062,7 @@
"dtype: int64"
]
},
"execution_count": 15,
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1032,7 +1081,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 19,
"metadata": {},
"outputs": [
{
......
This diff is collapsed.
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