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
agatheS
mooc-rr
Commits
e404e2d1
Commit
e404e2d1
authored
Apr 03, 2020
by
agatheS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update exercice : work with dates
parent
98e727d9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
434 additions
and
5 deletions
+434
-5
exercice.ipynb
module2/exo4/exercice.ipynb
+434
-5
No files found.
module2/exo4/exercice.ipynb
View file @
e404e2d1
...
@@ -16,30 +16,459 @@
...
@@ -16,30 +16,459 @@
"metadata": {
"metadata": {
"scrolled": true
"scrolled": true
},
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/home/jovyan/work/module2/exo4\n"
]
}
],
"source": [
"import os\n",
"mypath=os.getcwd()\n",
"print(mypath)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"C'est là qu'on est"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"hideOutput": true
},
"outputs": [
"outputs": [
{
{
"data": {
"data": {
"text/plain": [
"text/plain": [
"'/home/jovyan/work/module2/exo4'"
"['exercice_python_en.org',\n",
" 'exercice_fr.ipynb',\n",
" 'exercice.ipynb',\n",
" 'exercice_fr.Rmd',\n",
" 'exercice_python_fr.org',\n",
" 'exercice_R_en.org',\n",
" 'exercice_R_fr.org',\n",
" 'exercice_en.Rmd',\n",
" 'exercice_en.ipynb',\n",
" '.ipynb_checkpoints',\n",
" 'donnees.csv']"
]
]
},
},
"execution_count":
1
,
"execution_count":
2
,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
],
],
"source": [
"source": [
"
pwd
"
"
os.listdir(mypath)
"
]
]
},
},
{
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/home/jovyan/work/module2/exo4/*.csv\n"
]
}
],
"source": [
"source": [
"C'est là qu'on est"
"print(mypath + \"/*.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['donnees.csv']\n"
]
}
],
"source": [
"import glob\n",
"csvlist = [f for f in glob.glob(\"*.csv\")]\n",
"print(csvlist)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"donnees.csv\n"
]
}
],
"source": [
"filename=csvlist[0]\n",
"print(filename)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": true
},
"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>Unnamed: 0</th>\n",
" <th>date</th>\n",
" <th>sport</th>\n",
" <th>durée</th>\n",
" <th>FC moy</th>\n",
" <th>FC max</th>\n",
" <th>intensité ressentie</th>\n",
" <th>Unnamed: 7</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>NaN</td>\n",
" <td>-----</td>\n",
" <td>-----</td>\n",
" <td>------</td>\n",
" <td>------</td>\n",
" <td>-------</td>\n",
" <td>-------------------</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>NaN</td>\n",
" <td>18/03/2020</td>\n",
" <td>vélo</td>\n",
" <td>1:09:16</td>\n",
" <td>128</td>\n",
" <td>176</td>\n",
" <td>facile</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>NaN</td>\n",
" <td>19/03/2020</td>\n",
" <td>vélo</td>\n",
" <td>2:29:58</td>\n",
" <td>151</td>\n",
" <td>188</td>\n",
" <td>mod+</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>NaN</td>\n",
" <td>20/03/2020</td>\n",
" <td>vélo</td>\n",
" <td>0:44:05</td>\n",
" <td>144</td>\n",
" <td>176</td>\n",
" <td>facile</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>NaN</td>\n",
" <td>25/03/2020</td>\n",
" <td>crossfit</td>\n",
" <td>0:51:25</td>\n",
" <td>128</td>\n",
" <td>182</td>\n",
" <td>mod+</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Unnamed: 0 date sport durée FC moy FC max \\\n",
"0 NaN ----- ----- ------ ------ ------- \n",
"1 NaN 18/03/2020 vélo 1:09:16 128 176 \n",
"2 NaN 19/03/2020 vélo 2:29:58 151 188 \n",
"3 NaN 20/03/2020 vélo 0:44:05 144 176 \n",
"4 NaN 25/03/2020 crossfit 0:51:25 128 182 \n",
"\n",
" intensité ressentie Unnamed: 7 \n",
"0 ------------------- NaN \n",
"1 facile NaN \n",
"2 mod+ NaN \n",
"3 facile NaN \n",
"4 mod+ NaN "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"variable = pd.read_csv(r\"/home/jovyan/work/module2/exo4/donnees.csv\",sep=';')\n",
"variable.head()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"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>date</th>\n",
" <th>sport</th>\n",
" <th>durée</th>\n",
" <th>FC moy</th>\n",
" <th>FC max</th>\n",
" <th>intensité ressentie</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>18/03/2020</td>\n",
" <td>vélo</td>\n",
" <td>1:09:16</td>\n",
" <td>128</td>\n",
" <td>176</td>\n",
" <td>facile</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>19/03/2020</td>\n",
" <td>vélo</td>\n",
" <td>2:29:58</td>\n",
" <td>151</td>\n",
" <td>188</td>\n",
" <td>mod+</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>20/03/2020</td>\n",
" <td>vélo</td>\n",
" <td>0:44:05</td>\n",
" <td>144</td>\n",
" <td>176</td>\n",
" <td>facile</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>25/03/2020</td>\n",
" <td>crossfit</td>\n",
" <td>0:51:25</td>\n",
" <td>128</td>\n",
" <td>182</td>\n",
" <td>mod+</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>26/03/2020</td>\n",
" <td>vélo</td>\n",
" <td>0:45:29</td>\n",
" <td>162</td>\n",
" <td>193</td>\n",
" <td>mod++</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" date sport durée FC moy FC max intensité ressentie \n",
"0 18/03/2020 vélo 1:09:16 128 176 facile \n",
"1 19/03/2020 vélo 2:29:58 151 188 mod+ \n",
"2 20/03/2020 vélo 0:44:05 144 176 facile \n",
"3 25/03/2020 crossfit 0:51:25 128 182 mod+ \n",
"4 26/03/2020 vélo 0:45:29 162 193 mod++ "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"variable = pd.read_csv(r\"/home/jovyan/work/module2/exo4/donnees.csv\",sep=';',header=0,usecols=[1,2,3,4,5,6],skiprows=[1],skipinitialspace=1)\n",
"variable.head()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"hideOutput": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[['18/03/2020 ' 'vélo ' '1:09:16 ' 128 176 'facile ']\n",
" ['19/03/2020 ' 'vélo ' '2:29:58 ' 151 188 'mod+ ']\n",
" ['20/03/2020 ' 'vélo ' '0:44:05 ' 144 176 'facile ']\n",
" ['25/03/2020 ' 'crossfit ' '0:51:25 ' 128 182 'mod+ ']\n",
" ['26/03/2020 ' 'vélo ' '0:45:29 ' 162 193 'mod++ ']\n",
" ['30/03/2020 ' 'cap ' '0:39:04 ' 158 189 'mod++ ']\n",
" ['30/03/2020 ' 'crossfit ' '0:29:14 ' 130 169 'mod+ ']\n",
" ['31/03/2020 ' 'vélo ' '0:41:52 ' 156 181 'mod+ ']\n",
" ['01/04/2020 ' 'vélo ' '0:39:06 ' 168 190 'mod++ ']]\n"
]
}
],
"source": [
"mat=variable.values\n",
"print(mat)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"9\n"
]
]
}
}
],
],
"source": [
"[nrows,ncols]=mat.shape\n",
"print(nrows)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['18/03/2020 ', '19/03/2020 ', '20/03/2020 ', '25/03/2020 ',\n",
" '26/03/2020 ', '30/03/2020 ', '30/03/2020 ', '31/03/2020 ',\n",
" '01/04/2020 '], dtype=object)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat[:,0]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'18/03/2020 '"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat[0,0]"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2020, 3, 18, 0, 0)"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from datetime import datetime, date, time, timezone\n",
"datetime.strptime(mat[0,0],\"%d/%m/%Y \")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"metadata": {
"kernelspec": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3",
...
...
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