|
541 | 541 | }, |
542 | 542 | "outputs": [], |
543 | 543 | "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", |
544 | 553 | "# 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')" |
547 | 555 | ] |
548 | 556 | }, |
549 | 557 | { |
|
555 | 563 | }, |
556 | 564 | "outputs": [], |
557 | 565 | "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", |
558 | 575 | "# 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')" |
561 | 577 | ] |
562 | 578 | }, |
563 | 579 | { |
|
653 | 669 | }, |
654 | 670 | "outputs": [], |
655 | 671 | "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')" |
659 | 676 | ] |
660 | 677 | }, |
661 | 678 | { |
|
667 | 684 | }, |
668 | 685 | "outputs": [], |
669 | 686 | "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')" |
673 | 691 | ] |
674 | 692 | }, |
675 | 693 | { |
|
0 commit comments