import local des données

parent 9163ccb7
...@@ -9,14 +9,16 @@ ...@@ -9,14 +9,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"%matplotlib inline\n", "%matplotlib inline\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
"import pandas as pd\n", "import pandas as pd\n",
"import isoweek" "import isoweek\n",
"import os\n",
"import urllib.request"
] ]
}, },
{ {
...@@ -28,10 +30,8 @@ ...@@ -28,10 +30,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"data_url = \"http://www.sentiweb.fr/datasets/incidence-PAY-3.csv\"" "data_url = \"http://www.sentiweb.fr/datasets/incidence-PAY-3.csv\""
...@@ -59,14 +59,150 @@ ...@@ -59,14 +59,150 @@
"La première ligne du fichier CSV est un commentaire, que nous ignorons en précisant `skiprows=1`." "La première ligne du fichier CSV est un commentaire, que nous ignorons en précisant `skiprows=1`."
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Il se peut que l'URl change et devienne caduque au fil du temps. Ce fichier va d'abord tenter d'importer une copie locale si elle est disponible, sinon charger l'URL et créer le fichier. "
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"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>week</th>\n",
" <th>indicator</th>\n",
" <th>inc</th>\n",
" <th>inc_low</th>\n",
" <th>inc_up</th>\n",
" <th>inc100</th>\n",
" <th>inc100_low</th>\n",
" <th>inc100_up</th>\n",
" <th>geo_insee</th>\n",
" <th>geo_name</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>202011</td>\n",
" <td>3</td>\n",
" <td>101704</td>\n",
" <td>93652.0</td>\n",
" <td>109756.0</td>\n",
" <td>154</td>\n",
" <td>142.0</td>\n",
" <td>166.0</td>\n",
" <td>FR</td>\n",
" <td>France</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>202010</td>\n",
" <td>3</td>\n",
" <td>104977</td>\n",
" <td>96650.0</td>\n",
" <td>113304.0</td>\n",
" <td>159</td>\n",
" <td>146.0</td>\n",
" <td>172.0</td>\n",
" <td>FR</td>\n",
" <td>France</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>202009</td>\n",
" <td>3</td>\n",
" <td>110696</td>\n",
" <td>102066.0</td>\n",
" <td>119326.0</td>\n",
" <td>168</td>\n",
" <td>155.0</td>\n",
" <td>181.0</td>\n",
" <td>FR</td>\n",
" <td>France</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>202008</td>\n",
" <td>3</td>\n",
" <td>143753</td>\n",
" <td>133984.0</td>\n",
" <td>153522.0</td>\n",
" <td>218</td>\n",
" <td>203.0</td>\n",
" <td>233.0</td>\n",
" <td>FR</td>\n",
" <td>France</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>202007</td>\n",
" <td>3</td>\n",
" <td>183610</td>\n",
" <td>172812.0</td>\n",
" <td>194408.0</td>\n",
" <td>279</td>\n",
" <td>263.0</td>\n",
" <td>295.0</td>\n",
" <td>FR</td>\n",
" <td>France</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" week indicator inc inc_low inc_up inc100 inc100_low \\\n",
"0 202011 3 101704 93652.0 109756.0 154 142.0 \n",
"1 202010 3 104977 96650.0 113304.0 159 146.0 \n",
"2 202009 3 110696 102066.0 119326.0 168 155.0 \n",
"3 202008 3 143753 133984.0 153522.0 218 203.0 \n",
"4 202007 3 183610 172812.0 194408.0 279 263.0 \n",
"\n",
" inc100_up geo_insee geo_name \n",
"0 166.0 FR France \n",
"1 172.0 FR France \n",
"2 181.0 FR France \n",
"3 233.0 FR France \n",
"4 295.0 FR France "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"raw_data = pd.read_csv(data_url, skiprows=1)\n", "filename = \"./syndrome-grippal.csv\"\n",
"raw_data" "\n",
"if not os.path.exists(filename):\n",
" urllib.request.urlretrieve(data_url, filename)\n",
"\n",
"raw_data = pd.read_csv(filename, skiprows=1)\n",
"raw_data.head()"
] ]
}, },
{ {
...@@ -364,7 +500,7 @@ ...@@ -364,7 +500,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.1" "version": "3.6.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
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