Test du changement du format year/week

parent 979a8cc0
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -996,7 +996,7 @@ ...@@ -996,7 +996,7 @@
"[1892 rows x 10 columns]" "[1892 rows x 10 columns]"
] ]
}, },
"execution_count": 5, "execution_count": 4,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1009,7 +1009,7 @@ ...@@ -1009,7 +1009,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1071,7 +1071,7 @@ ...@@ -1071,7 +1071,7 @@
"1655 FR France " "1655 FR France "
] ]
}, },
"execution_count": 7, "execution_count": 5,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1083,7 +1083,7 @@ ...@@ -1083,7 +1083,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -2048,7 +2048,7 @@ ...@@ -2048,7 +2048,7 @@
"[1891 rows x 10 columns]" "[1891 rows x 10 columns]"
] ]
}, },
"execution_count": 8, "execution_count": 6,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -2060,6 +2060,64 @@ ...@@ -2060,6 +2060,64 @@
"data" "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<ipython-input-9-e4ec19bfbf99>\u001b[0m in \u001b[0;36m<module>\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", "cell_type": "code",
"execution_count": null, "execution_count": null,
......
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