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
a12161f2df0e1aabd768453ba47e6d46
mooc-rr
Commits
5276df69
Commit
5276df69
authored
Mar 16, 2025
by
a12161f2df0e1aabd768453ba47e6d46
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exo fait
parent
928fea05
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
540 additions
and
3 deletions
+540
-3
test.ipynb
module2/exo1/test.ipynb
+399
-0
toy_notebook_fr.ipynb
module2/exo1/toy_notebook_fr.ipynb
+141
-3
No files found.
module2/exo1/test.ipynb
0 → 100644
View file @
5276df69
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Notebook Python R\n",
"\n",
"## Import des données dans Python"
]
},
{
"cell_type": "code",
"execution_count": 1,
"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>Unnamed: 0</th>\n",
" <th>speed</th>\n",
" <th>dist</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>7</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>7</td>\n",
" <td>22</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>8</td>\n",
" <td>16</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Unnamed: 0 speed dist\n",
"0 1 4 2\n",
"1 2 4 10\n",
"2 3 7 4\n",
"3 4 7 22\n",
"4 5 8 16"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"# data_url = \"https://forge.scilab.org/index.php/p/rdataset/source/file/master/csv/datasets/cars.csv\"\n",
"data_url = \"cars.csv\"\n",
"df_python = pd.read_csv(data_url)\n",
"df_python.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Supression de la première colonne"
]
},
{
"cell_type": "code",
"execution_count": 2,
"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>speed</th>\n",
" <th>dist</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>4</td>\n",
" <td>10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>7</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>7</td>\n",
" <td>22</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>8</td>\n",
" <td>16</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" speed dist\n",
"0 4 2\n",
"1 4 10\n",
"2 7 4\n",
"3 7 22\n",
"4 8 16"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_python.drop(df_python.columns[[0]], axis=1, inplace=True)\n",
"df_python.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Summary avec Python"
]
},
{
"cell_type": "code",
"execution_count": 3,
"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>speed</th>\n",
" <th>dist</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>50.000000</td>\n",
" <td>50.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>15.400000</td>\n",
" <td>42.980000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>5.287644</td>\n",
" <td>25.769377</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>4.000000</td>\n",
" <td>2.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>12.000000</td>\n",
" <td>26.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>15.000000</td>\n",
" <td>36.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>19.000000</td>\n",
" <td>56.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>25.000000</td>\n",
" <td>120.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" speed dist\n",
"count 50.000000 50.000000\n",
"mean 15.400000 42.980000\n",
"std 5.287644 25.769377\n",
"min 4.000000 2.000000\n",
"25% 12.000000 26.000000\n",
"50% 15.000000 36.000000\n",
"75% 19.000000 56.000000\n",
"max 25.000000 120.000000"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_python.describe()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Summary avec R"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from rpy2.robjects import pandas2ri\n",
"pandas2ri.activate()\n",
"from rpy2.robjects.packages import importr"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" speed dist \n",
"\r\n",
" Min. : 4.0 Min. : 2.00 \n",
"\r\n",
" 1st Qu.:12.0 1st Qu.: 26.00 \n",
"\r\n",
" Median :15.0 Median : 36.00 \n",
"\r\n",
" Mean :15.4 Mean : 42.98 \n",
"\r\n",
" 3rd Qu.:19.0 3rd Qu.: 56.00 \n",
"\r\n",
" Max. :25.0 Max. :120.00 \n",
"\n"
]
}
],
"source": [
"base = importr('base')\n",
"print(base.summary(df_python))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\r\n",
" Numeric \n",
"\r\n",
" mean median var sd valid.n\n",
"\r\n",
"speed 15.40 15 27.96 5.29 50\n",
"\r\n",
"dist 42.98 36 664.06 25.77 50\n",
"\n"
]
}
],
"source": [
"prettyR = importr('prettyR')\n",
"print(prettyR.describe(df_python))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Liens utiles\n",
"\n",
"- http://rpy.sourceforge.net/rpy2/doc-2.4/html/introduction.html\n",
"- https://rpy2.readthedocs.io/en/version_2.8.x/"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
module2/exo1/toy_notebook_fr.ipynb
View file @
5276df69
This diff is collapsed.
Click to expand it.
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