From 2654341bb84d12282a147562d0cf903ec5d31188 Mon Sep 17 00:00:00 2001 From: 521adc37f04e8509ebf5ce131815aa0a <521adc37f04e8509ebf5ce131815aa0a@app-learninglab.inria.fr> Date: Sat, 6 Feb 2021 12:44:54 +0000 Subject: [PATCH] Test du changement du format year/week --- module3/exo2/exercice.ipynb | 72 +++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/module3/exo2/exercice.ipynb b/module3/exo2/exercice.ipynb index e55117d..c059551 100644 --- a/module3/exo2/exercice.ipynb +++ b/module3/exo2/exercice.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -996,7 +996,7 @@ "[1892 rows x 10 columns]" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -1009,7 +1009,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -1071,7 +1071,7 @@ "1655 FR France " ] }, - "execution_count": 7, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -1083,7 +1083,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -2048,7 +2048,7 @@ "[1891 rows x 10 columns]" ] }, - "execution_count": 8, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -2060,6 +2060,64 @@ "data" ] }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1984-10-29\n" + ] + } + ], + "source": [ + "# Changer le format Année/Semaine exp 1984/44\n", + "year_and_week_int = 198444\n", + "year_and_week_str = str(year_and_week_int)\n", + "year = int(year_and_week_str[:4])\n", + "week = int(year_and_week_str[4:])\n", + "w = isoweek.Week(year, week)\n", + "print(w.day(0))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'sorted_data' 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\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m first_spetember_week = [pd.Period(pd.Timestamp(y, 9, 1), 'w')\n\u001b[0;32m----> 4\u001b[0;31m for y in range(sorted_data.index[0].year,\n\u001b[0m\u001b[1;32m 5\u001b[0m sorted_data.index[-1].year)]\n", + "\u001b[0;31mNameError\u001b[0m: name 'sorted_data' is not defined" + ] + } + ], + "source": [ + "# Choisir le 1er spetembre comme début de chaque période anuelle\n", + "\n", + "first_spetember_week = [pd.Period(pd.Timestamp(y, 9, 1), 'w')\n", + " for y in range(sorted_data.index[0].year,\n", + " sorted_data.index[-1].year)]\n", + "\n", + "\n", + "year = []\n", + "yearly_incidence = []\n", + "for week1, week2 in zip(first_september_week[:-1],\n", + " first_september_week[1:]):\n", + " one_year = sorted_data['inc'][week1:week2-1]\n", + " assert abs(len(one_year)-52) < 2\n", + " yearly_incidence.append(one_year.sum())\n", + " year.append(week2.year)" + ] + }, { "cell_type": "code", "execution_count": null, -- 2.18.1