Skip to content

Commit 45034b9

Browse files
committed
Tableaux croisés dynamiques après les groupes
1 parent 9d3656e commit 45034b9

File tree

5 files changed

+260
-6
lines changed

5 files changed

+260
-6
lines changed

en/01-dataframe.ipynb

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,49 @@
370370
"surveys_df.groupby(['species_id', 'sex'])###"
371371
]
372372
},
373+
{
374+
"cell_type": "markdown",
375+
"id": "7ad65751-a3da-4b2b-8f9e-7aeeb44e4f23",
376+
"metadata": {
377+
"lang": "en"
378+
},
379+
"source": [
380+
"## Pivot tables"
381+
]
382+
},
383+
{
384+
"cell_type": "code",
385+
"execution_count": null,
386+
"id": "7c22df2f-041f-46d0-9704-c54da1e7125e",
387+
"metadata": {
388+
"lang": "en,fr",
389+
"tags": [
390+
"exer"
391+
]
392+
},
393+
"outputs": [],
394+
"source": [
395+
"surveys_df.groupby(\n",
396+
" ['species_id', 'sex']\n",
397+
")['hindfoot_length'].median()#.unstack()#.head()"
398+
]
399+
},
400+
{
401+
"cell_type": "code",
402+
"execution_count": null,
403+
"id": "d6ea30c5-4904-4efa-8111-611eba05f986",
404+
"metadata": {
405+
"lang": "en,fr"
406+
},
407+
"outputs": [],
408+
"source": [
409+
"surveys_df.pivot_table(\n",
410+
" values='hindfoot_length',\n",
411+
" index='species_id',\n",
412+
" columns='sex',\n",
413+
" aggfunc='median').head()"
414+
]
415+
},
373416
{
374417
"cell_type": "markdown",
375418
"id": "ccff77fd-99c7-428e-854e-f771da6851a1",
@@ -394,7 +437,9 @@
394437
"* **Grouping by values** of one or many columns:\n",
395438
" * `groupby(column_name)`\n",
396439
" * `groupby([column_name1, column_name2])`\n",
397-
"* **Reshaping a DataFrame** from values in the index: `unstack()`"
440+
"* **Pivot tables**\n",
441+
" * Reshaping a DataFrame from values in the index: `unstack()`\n",
442+
" * Aggregation in a pivot table: `pivot_table()`"
398443
]
399444
},
400445
{

fr/01-dataframe.ipynb

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,49 @@
371371
"surveys_df.groupby(['species_id', 'sex'])###"
372372
]
373373
},
374+
{
375+
"cell_type": "markdown",
376+
"id": "9aff1b4a-4bae-4a4f-9e31-cc516daf41e5",
377+
"metadata": {
378+
"lang": "fr"
379+
},
380+
"source": [
381+
"## Tableaux croisés dynamiques"
382+
]
383+
},
384+
{
385+
"cell_type": "code",
386+
"execution_count": null,
387+
"id": "7c22df2f-041f-46d0-9704-c54da1e7125e",
388+
"metadata": {
389+
"lang": "en,fr",
390+
"tags": [
391+
"exer"
392+
]
393+
},
394+
"outputs": [],
395+
"source": [
396+
"surveys_df.groupby(\n",
397+
" ['species_id', 'sex']\n",
398+
")['hindfoot_length'].median()#.unstack()#.head()"
399+
]
400+
},
401+
{
402+
"cell_type": "code",
403+
"execution_count": null,
404+
"id": "d6ea30c5-4904-4efa-8111-611eba05f986",
405+
"metadata": {
406+
"lang": "en,fr"
407+
},
408+
"outputs": [],
409+
"source": [
410+
"surveys_df.pivot_table(\n",
411+
" values='hindfoot_length',\n",
412+
" index='species_id',\n",
413+
" columns='sex',\n",
414+
" aggfunc='median').head()"
415+
]
416+
},
374417
{
375418
"cell_type": "markdown",
376419
"id": "a96f6358-ba62-4a01-b95f-df05e771fceb",
@@ -395,7 +438,9 @@
395438
"* **Grouper selon les valeurs** d'une ou plusieurs colonnes :\n",
396439
" * `groupby(nom_col)`\n",
397440
" * `groupby([nom_col1, nom_col2])`\n",
398-
"* **Transformer le DataFrame** : `unstack()`"
441+
"* **Tableaux croisés dynamiques**\n",
442+
" * Transformation selon les valeurs de l'index : `unstack()`\n",
443+
" * Aggrégation dans un tableau croisé dynamique : `pivot_table()`"
399444
]
400445
},
401446
{

solution-en/01-dataframe.ipynb

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,49 @@
373373
"surveys_df.groupby(['species_id', 'sex']).mean(numeric_only=True)"
374374
]
375375
},
376+
{
377+
"cell_type": "markdown",
378+
"id": "7ad65751-a3da-4b2b-8f9e-7aeeb44e4f23",
379+
"metadata": {
380+
"lang": "en"
381+
},
382+
"source": [
383+
"## Pivot tables"
384+
]
385+
},
386+
{
387+
"cell_type": "code",
388+
"execution_count": null,
389+
"id": "a4831e8b-2235-46aa-ab5e-1169edf81288",
390+
"metadata": {
391+
"lang": "en,fr",
392+
"tags": [
393+
"soln"
394+
]
395+
},
396+
"outputs": [],
397+
"source": [
398+
"surveys_df.groupby(\n",
399+
" ['species_id', 'sex']\n",
400+
")['hindfoot_length'].median().unstack().head()"
401+
]
402+
},
403+
{
404+
"cell_type": "code",
405+
"execution_count": null,
406+
"id": "d6ea30c5-4904-4efa-8111-611eba05f986",
407+
"metadata": {
408+
"lang": "en,fr"
409+
},
410+
"outputs": [],
411+
"source": [
412+
"surveys_df.pivot_table(\n",
413+
" values='hindfoot_length',\n",
414+
" index='species_id',\n",
415+
" columns='sex',\n",
416+
" aggfunc='median').head()"
417+
]
418+
},
376419
{
377420
"cell_type": "markdown",
378421
"id": "ccff77fd-99c7-428e-854e-f771da6851a1",
@@ -397,7 +440,9 @@
397440
"* **Grouping by values** of one or many columns:\n",
398441
" * `groupby(column_name)`\n",
399442
" * `groupby([column_name1, column_name2])`\n",
400-
"* **Reshaping a DataFrame** from values in the index: `unstack()`"
443+
"* **Pivot tables**\n",
444+
" * Reshaping a DataFrame from values in the index: `unstack()`\n",
445+
" * Aggregation in a pivot table: `pivot_table()`"
401446
]
402447
},
403448
{

solution-fr/01-dataframe.ipynb

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,49 @@
374374
"surveys_df.groupby(['species_id', 'sex']).mean(numeric_only=True)"
375375
]
376376
},
377+
{
378+
"cell_type": "markdown",
379+
"id": "9aff1b4a-4bae-4a4f-9e31-cc516daf41e5",
380+
"metadata": {
381+
"lang": "fr"
382+
},
383+
"source": [
384+
"## Tableaux croisés dynamiques"
385+
]
386+
},
387+
{
388+
"cell_type": "code",
389+
"execution_count": null,
390+
"id": "a4831e8b-2235-46aa-ab5e-1169edf81288",
391+
"metadata": {
392+
"lang": "en,fr",
393+
"tags": [
394+
"soln"
395+
]
396+
},
397+
"outputs": [],
398+
"source": [
399+
"surveys_df.groupby(\n",
400+
" ['species_id', 'sex']\n",
401+
")['hindfoot_length'].median().unstack().head()"
402+
]
403+
},
404+
{
405+
"cell_type": "code",
406+
"execution_count": null,
407+
"id": "d6ea30c5-4904-4efa-8111-611eba05f986",
408+
"metadata": {
409+
"lang": "en,fr"
410+
},
411+
"outputs": [],
412+
"source": [
413+
"surveys_df.pivot_table(\n",
414+
" values='hindfoot_length',\n",
415+
" index='species_id',\n",
416+
" columns='sex',\n",
417+
" aggfunc='median').head()"
418+
]
419+
},
377420
{
378421
"cell_type": "markdown",
379422
"id": "a96f6358-ba62-4a01-b95f-df05e771fceb",
@@ -398,7 +441,9 @@
398441
"* **Grouper selon les valeurs** d'une ou plusieurs colonnes :\n",
399442
" * `groupby(nom_col)`\n",
400443
" * `groupby([nom_col1, nom_col2])`\n",
401-
"* **Transformer le DataFrame** : `unstack()`"
444+
"* **Tableaux croisés dynamiques**\n",
445+
" * Transformation selon les valeurs de l'index : `unstack()`\n",
446+
" * Aggrégation dans un tableau croisé dynamique : `pivot_table()`"
402447
]
403448
},
404449
{

src/01-dataframe.ipynb

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,76 @@
883883
"surveys_df.groupby(['species_id', 'sex'])###"
884884
]
885885
},
886+
{
887+
"cell_type": "markdown",
888+
"id": "9aff1b4a-4bae-4a4f-9e31-cc516daf41e5",
889+
"metadata": {
890+
"lang": "fr"
891+
},
892+
"source": [
893+
"## Tableaux croisés dynamiques"
894+
]
895+
},
896+
{
897+
"cell_type": "markdown",
898+
"id": "7ad65751-a3da-4b2b-8f9e-7aeeb44e4f23",
899+
"metadata": {
900+
"lang": "en"
901+
},
902+
"source": [
903+
"## Pivot tables"
904+
]
905+
},
906+
{
907+
"cell_type": "code",
908+
"execution_count": null,
909+
"id": "a4831e8b-2235-46aa-ab5e-1169edf81288",
910+
"metadata": {
911+
"lang": "en,fr",
912+
"tags": [
913+
"soln"
914+
]
915+
},
916+
"outputs": [],
917+
"source": [
918+
"surveys_df.groupby(\n",
919+
" ['species_id', 'sex']\n",
920+
")['hindfoot_length'].median().unstack().head()"
921+
]
922+
},
923+
{
924+
"cell_type": "code",
925+
"execution_count": null,
926+
"id": "7c22df2f-041f-46d0-9704-c54da1e7125e",
927+
"metadata": {
928+
"lang": "en,fr",
929+
"tags": [
930+
"exer"
931+
]
932+
},
933+
"outputs": [],
934+
"source": [
935+
"surveys_df.groupby(\n",
936+
" ['species_id', 'sex']\n",
937+
")['hindfoot_length'].median()#.unstack()#.head()"
938+
]
939+
},
940+
{
941+
"cell_type": "code",
942+
"execution_count": null,
943+
"id": "d6ea30c5-4904-4efa-8111-611eba05f986",
944+
"metadata": {
945+
"lang": "en,fr"
946+
},
947+
"outputs": [],
948+
"source": [
949+
"surveys_df.pivot_table(\n",
950+
" values='hindfoot_length',\n",
951+
" index='species_id',\n",
952+
" columns='sex',\n",
953+
" aggfunc='median').head()"
954+
]
955+
},
886956
{
887957
"cell_type": "markdown",
888958
"id": "a96f6358-ba62-4a01-b95f-df05e771fceb",
@@ -907,7 +977,9 @@
907977
"* **Grouper selon les valeurs** d'une ou plusieurs colonnes :\n",
908978
" * `groupby(nom_col)`\n",
909979
" * `groupby([nom_col1, nom_col2])`\n",
910-
"* **Transformer le DataFrame** : `unstack()`"
980+
"* **Tableaux croisés dynamiques**\n",
981+
" * Transformation selon les valeurs de l'index : `unstack()`\n",
982+
" * Aggrégation dans un tableau croisé dynamique : `pivot_table()`"
911983
]
912984
},
913985
{
@@ -934,7 +1006,9 @@
9341006
"* **Grouping by values** of one or many columns:\n",
9351007
" * `groupby(column_name)`\n",
9361008
" * `groupby([column_name1, column_name2])`\n",
937-
"* **Reshaping a DataFrame** from values in the index: `unstack()`"
1009+
"* **Pivot tables**\n",
1010+
" * Reshaping a DataFrame from values in the index: `unstack()`\n",
1011+
" * Aggregation in a pivot table: `pivot_table()`"
9381012
]
9391013
},
9401014
{

0 commit comments

Comments
 (0)