Skip to content

Commit 5b8c8bc

Browse files
committed
Exemple fillna - afficher les count et std
1 parent f463e77 commit 5b8c8bc

File tree

5 files changed

+84
-30
lines changed

5 files changed

+84
-30
lines changed

en/03-format.ipynb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,17 @@
275275
},
276276
"outputs": [],
277277
"source": [
278+
"def state_by_species(df, column):\n",
279+
" print(\n",
280+
" df.groupby('species_id')[column].aggregate(\n",
281+
" ['count', 'mean', 'std']\n",
282+
" ).loc['DM':'NL']\n",
283+
" )\n",
284+
" print()\n",
285+
" print('Total count:', df[column].count())\n",
286+
"\n",
278287
"# Before the cleanup\n",
279-
"print('Total count :', surveys_df['weight'].count())\n",
280-
"surveys_df.groupby('species_id')['weight'].mean().loc['DM':'NL']"
288+
"state_by_species(surveys_df, 'weight')"
281289
]
282290
},
283291
{
@@ -331,9 +339,10 @@
331339
},
332340
"outputs": [],
333341
"source": [
334-
"# After the cleanup\n",
335-
"print('Total count :', copy_surveys['weight'].count())\n",
336-
"copy_surveys.groupby('species_id')['weight'].mean().loc['DM':'NL']"
342+
"# Before and after the cleanup\n",
343+
"state_by_species(surveys_df, 'weight')\n",
344+
"print() # Print an empty line\n",
345+
"state_by_species(copy_surveys, 'weight')"
337346
]
338347
},
339348
{

fr/03-format.ipynb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,17 @@
275275
},
276276
"outputs": [],
277277
"source": [
278+
"def etat_par_species(df, colonne):\n",
279+
" print(\n",
280+
" df.groupby('species_id')[colonne].aggregate(\n",
281+
" ['count', 'mean', 'std']\n",
282+
" ).loc['DM':'NL']\n",
283+
" )\n",
284+
" print()\n",
285+
" print('Décompte total :', df[colonne].count())\n",
286+
"\n",
278287
"# Avant le nettoyage\n",
279-
"print('Décompte total :', surveys_df['weight'].count())\n",
280-
"surveys_df.groupby('species_id')['weight'].mean().loc['DM':'NL']"
288+
"etat_par_species(surveys_df, 'weight')"
281289
]
282290
},
283291
{
@@ -331,9 +339,10 @@
331339
},
332340
"outputs": [],
333341
"source": [
334-
"# Après le nettoyage\n",
335-
"print('Décompte total :', copie_surveys['weight'].count())\n",
336-
"copie_surveys.groupby('species_id')['weight'].mean().loc['DM':'NL']"
342+
"# Avant et après le nettoyage\n",
343+
"etat_par_species(surveys_df, 'weight')\n",
344+
"print() # Afficher une ligne vide\n",
345+
"etat_par_species(copie_surveys, 'weight')"
337346
]
338347
},
339348
{

solution-en/03-format.ipynb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,17 @@
275275
},
276276
"outputs": [],
277277
"source": [
278+
"def state_by_species(df, column):\n",
279+
" print(\n",
280+
" df.groupby('species_id')[column].aggregate(\n",
281+
" ['count', 'mean', 'std']\n",
282+
" ).loc['DM':'NL']\n",
283+
" )\n",
284+
" print()\n",
285+
" print('Total count:', df[column].count())\n",
286+
"\n",
278287
"# Before the cleanup\n",
279-
"print('Total count :', surveys_df['weight'].count())\n",
280-
"surveys_df.groupby('species_id')['weight'].mean().loc['DM':'NL']"
288+
"state_by_species(surveys_df, 'weight')"
281289
]
282290
},
283291
{
@@ -331,9 +339,10 @@
331339
},
332340
"outputs": [],
333341
"source": [
334-
"# After the cleanup\n",
335-
"print('Total count :', copy_surveys['weight'].count())\n",
336-
"copy_surveys.groupby('species_id')['weight'].mean().loc['DM':'NL']"
342+
"# Before and after the cleanup\n",
343+
"state_by_species(surveys_df, 'weight')\n",
344+
"print() # Print an empty line\n",
345+
"state_by_species(copy_surveys, 'weight')"
337346
]
338347
},
339348
{

solution-fr/03-format.ipynb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,17 @@
275275
},
276276
"outputs": [],
277277
"source": [
278+
"def etat_par_species(df, colonne):\n",
279+
" print(\n",
280+
" df.groupby('species_id')[colonne].aggregate(\n",
281+
" ['count', 'mean', 'std']\n",
282+
" ).loc['DM':'NL']\n",
283+
" )\n",
284+
" print()\n",
285+
" print('Décompte total :', df[colonne].count())\n",
286+
"\n",
278287
"# Avant le nettoyage\n",
279-
"print('Décompte total :', surveys_df['weight'].count())\n",
280-
"surveys_df.groupby('species_id')['weight'].mean().loc['DM':'NL']"
288+
"etat_par_species(surveys_df, 'weight')"
281289
]
282290
},
283291
{
@@ -331,9 +339,10 @@
331339
},
332340
"outputs": [],
333341
"source": [
334-
"# Après le nettoyage\n",
335-
"print('Décompte total :', copie_surveys['weight'].count())\n",
336-
"copie_surveys.groupby('species_id')['weight'].mean().loc['DM':'NL']"
342+
"# Avant et après le nettoyage\n",
343+
"etat_par_species(surveys_df, 'weight')\n",
344+
"print() # Afficher une ligne vide\n",
345+
"etat_par_species(copie_surveys, 'weight')"
337346
]
338347
},
339348
{

src/03-format.ipynb

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,17 @@
541541
},
542542
"outputs": [],
543543
"source": [
544+
"def etat_par_species(df, colonne):\n",
545+
" print(\n",
546+
" df.groupby('species_id')[colonne].aggregate(\n",
547+
" ['count', 'mean', 'std']\n",
548+
" ).loc['DM':'NL']\n",
549+
" )\n",
550+
" print()\n",
551+
" print('Décompte total :', df[colonne].count())\n",
552+
"\n",
544553
"# Avant le nettoyage\n",
545-
"print('Décompte total :', surveys_df['weight'].count())\n",
546-
"surveys_df.groupby('species_id')['weight'].mean().loc['DM':'NL']"
554+
"etat_par_species(surveys_df, 'weight')"
547555
]
548556
},
549557
{
@@ -555,9 +563,17 @@
555563
},
556564
"outputs": [],
557565
"source": [
566+
"def state_by_species(df, column):\n",
567+
" print(\n",
568+
" df.groupby('species_id')[column].aggregate(\n",
569+
" ['count', 'mean', 'std']\n",
570+
" ).loc['DM':'NL']\n",
571+
" )\n",
572+
" print()\n",
573+
" print('Total count:', df[column].count())\n",
574+
"\n",
558575
"# Before the cleanup\n",
559-
"print('Total count :', surveys_df['weight'].count())\n",
560-
"surveys_df.groupby('species_id')['weight'].mean().loc['DM':'NL']"
576+
"state_by_species(surveys_df, 'weight')"
561577
]
562578
},
563579
{
@@ -653,9 +669,10 @@
653669
},
654670
"outputs": [],
655671
"source": [
656-
"# Après le nettoyage\n",
657-
"print('Décompte total :', copie_surveys['weight'].count())\n",
658-
"copie_surveys.groupby('species_id')['weight'].mean().loc['DM':'NL']"
672+
"# Avant et après le nettoyage\n",
673+
"etat_par_species(surveys_df, 'weight')\n",
674+
"print() # Afficher une ligne vide\n",
675+
"etat_par_species(copie_surveys, 'weight')"
659676
]
660677
},
661678
{
@@ -667,9 +684,10 @@
667684
},
668685
"outputs": [],
669686
"source": [
670-
"# After the cleanup\n",
671-
"print('Total count :', copy_surveys['weight'].count())\n",
672-
"copy_surveys.groupby('species_id')['weight'].mean().loc['DM':'NL']"
687+
"# Before and after the cleanup\n",
688+
"state_by_species(surveys_df, 'weight')\n",
689+
"print() # Print an empty line\n",
690+
"state_by_species(copy_surveys, 'weight')"
673691
]
674692
},
675693
{

0 commit comments

Comments
 (0)