diff --git a/module2/exo4/MONJOURNAL.csv b/module2/exo4/MONJOURNAL.csv
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/module2/exo4/exercice.ipynb b/module2/exo4/exercice.ipynb
index 0bbbe371b01e359e381e43239412d77bf53fb1fb..2641dfc9e86f6b747e8b3b0d6a9ae0a9a51470bb 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",
+ " Date | \n",
+ " Cahier | \n",
+ " événement | \n",
+ " heures_travail | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 04/01/2022 | \n",
+ " projet_arduino | \n",
+ " rdv_UCA | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 05/01/2022 | \n",
+ " partition_bach | \n",
+ " zoom_XR | \n",
+ " 12 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 06/01/2022 | \n",
+ " cello_vocalise | \n",
+ " rdv_CIRM | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 07/01/2022 | \n",
+ " formation_éthique | \n",
+ " cours_en_ligne | \n",
+ " 14 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 08/01/2022 | \n",
+ " projet_collège | \n",
+ " NaN | \n",
+ " 13 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 09/01/2022 | \n",
+ " partition_bach | \n",
+ " zoom_prof | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " 6 | \n",
+ " 10/01/2022 | \n",
+ " cello_vocalise | \n",
+ " répétition_CRR | \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ " 7 | \n",
+ " 11/01/2022 | \n",
+ " formation_articles | \n",
+ " concert_CRR | \n",
+ " 10 | \n",
+ "
\n",
+ " \n",
+ "
\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 0000000000000000000000000000000000000000..c8f2749b921496a6268733b0090abf22e3a99510
--- /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 0000000000000000000000000000000000000000..e8df76fd8623b0f990574e0149f6b8c691b9f48b
--- /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