From d6f6c65eda19bef19999a2d78c9c502d239c41ea Mon Sep 17 00:00:00 2001 From: e781032b8dde1731b8ff9e81d8330526 Date: Sat, 15 Jan 2022 00:49:01 +0000 Subject: [PATCH] done --- module2/exo4/MONJOURNAL.csv | 0 module2/exo4/exercice.ipynb | 409 +++++++++++++++++++++++++++++++++++- module2/exo4/innovators.csv | 4 + module2/exo4/myjournal.csv | 9 + 4 files changed, 419 insertions(+), 3 deletions(-) create mode 100644 module2/exo4/MONJOURNAL.csv create mode 100644 module2/exo4/innovators.csv create mode 100644 module2/exo4/myjournal.csv diff --git a/module2/exo4/MONJOURNAL.csv b/module2/exo4/MONJOURNAL.csv new file mode 100644 index 0000000..e69de29 diff --git a/module2/exo4/exercice.ipynb b/module2/exo4/exercice.ipynb index 0bbbe37..2641dfc 100644 --- a/module2/exo4/exercice.ipynb +++ b/module2/exo4/exercice.ipynb @@ -1,5 +1,409 @@ { - "cells": [], + "cells": [ + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "import csv\n", + "with open('myjournal.csv','w',newline='') as fichiercsv:\n", + " writer=csv.writer(fichiercsv)\n", + " writer.writerow(['Date', 'Cahier', 'événement', 'heures_travail'])\n", + " writer.writerow(['04/01/2022', 'projet_arduino', 'rdv_UCA', '8'])\n", + " writer.writerow(['05/01/2022', 'partition_bach', 'zoom_XR', '12'])\n", + " writer.writerow(['06/01/2022', 'cello_vocalise', 'rdv_CIRM', '9'])\n", + " writer.writerow(['07/01/2022', 'formation_éthique', 'cours_en_ligne', '14'])\n", + " writer.writerow(['08/01/2022', 'projet_collège', '', '13'])\n", + " writer.writerow(['09/01/2022', 'partition_bach', 'zoom_prof', '8'])\n", + " writer.writerow(['10/01/2022', 'cello_vocalise', 'répétition_CRR', '6'])\n", + " writer.writerow(['11/01/2022', 'formation_articles', 'concert_CRR', '10'])\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "04/01/2022 projet_arduino\n", + "05/01/2022 partition_bach\n", + "06/01/2022 cello_vocalise\n", + "07/01/2022 formation_éthique\n", + "08/01/2022 projet_collège\n", + "09/01/2022 partition_bach\n", + "10/01/2022 cello_vocalise\n", + "11/01/2022 formation_articles\n" + ] + } + ], + "source": [ + "\n", + " with open('myjournal.csv', newline='') as fichiercsv:\n", + " reader = csv.DictReader(fichiercsv)\n", + " for row in reader:\n", + " print(row['Date'], row['Cahier'])\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "rdv_UCA\n", + "zoom_XR\n", + "rdv_CIRM\n", + "cours_en_ligne\n", + "\n", + "zoom_prof\n", + "répétition_CRR\n", + "concert_CRR\n" + ] + } + ], + "source": [ + "\n", + " with open('myjournal.csv', newline='') as fichiercsv:\n", + " reader = csv.DictReader(fichiercsv)\n", + " for row in reader:\n", + " print(row['événement'])" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Date,Cahier,événement,heures_travail\\n']\n", + "['04/01/2022,projet_arduino,rdv_UCA,8\\n', '05/01/2022,partition_bach,zoom_XR,12\\n', '06/01/2022,cello_vocalise,rdv_CIRM,9\\n', '07/01/2022,formation_éthique,cours_en_ligne,14\\n', '08/01/2022,projet_collège,,13\\n', '09/01/2022,partition_bach,zoom_prof,8\\n', '10/01/2022,cello_vocalise,répétition_CRR,6\\n', '11/01/2022,formation_articles,concert_CRR,10\\n']\n" + ] + } + ], + "source": [ + "with open('myjournal.csv') as file:\n", + " content = file.readlines()\n", + "header = content[:1]\n", + "rows = content[1:]\n", + "print(header)\n", + "print(rows)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateCahierévénementheures_travail
004/01/2022projet_arduinordv_UCA8
105/01/2022partition_bachzoom_XR12
206/01/2022cello_vocaliserdv_CIRM9
307/01/2022formation_éthiquecours_en_ligne14
408/01/2022projet_collègeNaN13
509/01/2022partition_bachzoom_prof8
610/01/2022cello_vocaliserépétition_CRR6
711/01/2022formation_articlesconcert_CRR10
\n", + "
" + ], + "text/plain": [ + " Date Cahier événement heures_travail\n", + "0 04/01/2022 projet_arduino rdv_UCA 8\n", + "1 05/01/2022 partition_bach zoom_XR 12\n", + "2 06/01/2022 cello_vocalise rdv_CIRM 9\n", + "3 07/01/2022 formation_éthique cours_en_ligne 14\n", + "4 08/01/2022 projet_collège NaN 13\n", + "5 09/01/2022 partition_bach zoom_prof 8\n", + "6 10/01/2022 cello_vocalise répétition_CRR 6\n", + "7 11/01/2022 formation_articles concert_CRR 10" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data= pd.read_csv(\"myjournal.csv\")\n", + "data\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['Date', 'Cahier', 'événement', 'heures_travail'], dtype='object')" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.columns" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('cello_vocalise', 7.5)\n", + "('formation_articles', 10.0)\n", + "('formation_éthique', 14.0)\n", + "('partition_bach', 10.0)\n", + "('projet_arduino', 8.0)\n", + "('projet_collège', 13.0)\n" + ] + } + ], + "source": [ + "import pandas as pd\n", + "data= pd.read_csv(\"myjournal.csv\")\n", + "\n", + "groupby_gender = data.groupby('Cahier')\n", + "for gender, value in groupby_gender['heures_travail']:\n", + " print((gender, value.mean()))" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10.0\n", + "80\n", + "14\n", + "6\n", + "8\n", + "9.5\n", + "2.7774602993176543\n", + "7.714285714285714\n" + ] + } + ], + "source": [ + "data= pd.read_csv(\"myjournal.csv\")\n", + "\n", + "mean1 = data['heures_travail'].mean()\n", + "sum1 = data['heures_travail'].sum()\n", + "max1 = data['heures_travail'].max()\n", + "min1 = data['heures_travail'].min()\n", + "count1 = data['heures_travail'].count()\n", + "median1 = data['heures_travail'].median() \n", + "std1 = data['heures_travail'].std() \n", + "var1 = data['heures_travail'].var() \n", + "\n", + "print(mean1)\n", + "print(sum1)\n", + "print(max1)\n", + "print(min1)\n", + "print(count1)\n", + "print(median1)\n", + "print(std1)\n", + "print(var1)" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{partition_bach: 2 } {# of rows: 2 }\n" + ] + } + ], + "source": [ + "my_reader = open('myjournal.csv', encoding = 'utf-8')\n", + "rows = 0\n", + "partition_bach = 0\n", + "\n", + "for record in my_reader:\n", + " if record.count('partition_bach') > 0:\n", + " rows += 1\n", + " partition_bach += record.count('partition_bach')\n", + "\n", + "print('{partition_bach: %d } {# of rows: %d }' % (partition_bach, rows))\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{projet: 2 } {# of rows: 2 }\n" + ] + } + ], + "source": [ + "my_reader = open('myjournal.csv', encoding = 'utf-8')\n", + "rows = 0\n", + "projet = 0\n", + "\n", + "for record in my_reader:\n", + " if record.count('projet') > 0:\n", + " rows += 1\n", + " projet += record.count('projet')\n", + "\n", + "print('{projet: %d } {# of rows: %d }' % (projet, rows))" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{arduino: 1 } {# of rows: 1 }\n" + ] + } + ], + "source": [ + "my_reader = open('myjournal.csv', encoding = 'utf-8')\n", + "rows = 0\n", + "arduino = 0\n", + "\n", + "for record in my_reader:\n", + " if record.count('arduino') > 0:\n", + " rows += 1\n", + " arduino += record.count('arduino')\n", + "\n", + "print('{arduino: %d } {# of rows: %d }' % (arduino, rows))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], "metadata": { "kernelspec": { "display_name": "Python 3", @@ -16,10 +420,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.3" + "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 } - diff --git a/module2/exo4/innovators.csv b/module2/exo4/innovators.csv new file mode 100644 index 0000000..c8f2749 --- /dev/null +++ b/module2/exo4/innovators.csv @@ -0,0 +1,4 @@ +SN,Name,Contribution +1,Linus Torvalds,Linux Kernel +2,Tim Berners-Lee,World Wide Web +3,Guido van Rossum,Python Programming diff --git a/module2/exo4/myjournal.csv b/module2/exo4/myjournal.csv new file mode 100644 index 0000000..e8df76f --- /dev/null +++ b/module2/exo4/myjournal.csv @@ -0,0 +1,9 @@ +Date,Cahier,événement,heures_travail +04/01/2022,projet_arduino,rdv_UCA,8 +05/01/2022,partition_bach,zoom_XR,12 +06/01/2022,cello_vocalise,rdv_CIRM,9 +07/01/2022,formation_éthique,cours_en_ligne,14 +08/01/2022,projet_collège,,13 +09/01/2022,partition_bach,zoom_prof,8 +10/01/2022,cello_vocalise,répétition_CRR,6 +11/01/2022,formation_articles,concert_CRR,10 -- 2.18.1