{ "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", "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.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }