Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mooc-rr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
33e962b28c2cd12d54c77ebe17cb6891
mooc-rr
Commits
cea7e08a
Commit
cea7e08a
authored
Jan 04, 2022
by
33e962b28c2cd12d54c77ebe17cb6891
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chickenpox
parent
50416ca4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
3 deletions
+87
-3
exercice.ipynb
module3/exo2/exercice.ipynb
+87
-3
No files found.
module3/exo2/exercice.ipynb
View file @
cea7e08a
{
{
"cells": [],
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import isoweek"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def convert_week(year_and_week_int):\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",
" return pd.Period(w.day(0), 'W')"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2020 221186\n",
"2002 516689\n",
"2018 542312\n",
"2017 551041\n",
"1996 564901\n",
"2019 584066\n",
"2015 604382\n",
"2000 617597\n",
"2001 619041\n",
"2012 624573\n",
"2005 628464\n",
"2006 632833\n",
"2011 642368\n",
"1993 643387\n",
"1995 652478\n",
"1994 661409\n",
"1998 677775\n",
"1997 683434\n",
"2014 685769\n",
"2013 698332\n",
"2007 717352\n",
"2008 749478\n",
"1999 756456\n",
"2003 758363\n",
"2004 777388\n",
"2016 782114\n",
"2010 829911\n",
"1992 832939\n",
"2009 842373\n",
"dtype: int64"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = pd.read_csv(\"https://www.sentiweb.fr/datasets/incidence-PAY-7.csv\", skiprows=1).dropna().copy()\n",
"data['period'] = [convert_week(yw) for yw in data['week']]\n",
"sorted_data = data.set_index('period').sort_index()\n",
"first_september_week = [pd.Period(pd.Timestamp(y, 9, 1), 'W') for y in range(1991, sorted_data.index[-1].year)]\n",
"year = []\n",
"yearly_incidence = []\n",
"for week1, week2 in zip(first_september_week[:-1], 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)\n",
"pd.Series(data=yearly_incidence, index=year).sort_values()"
]
}
],
"metadata": {
"metadata": {
"kernelspec": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3",
...
@@ -16,10 +101,9 @@
...
@@ -16,10 +101,9 @@
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.6.
3
"
"version": "3.6.
4
"
}
}
},
},
"nbformat": 4,
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 2
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment