{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "title : \"Notes et moyennes pondérées en L3 Mathématiques\"\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"alert alert-block alert-info\">\n",
    "\n",
    "## Exercice\n",
    "\n",
    "On s’intéresse aux résultats d’un étudiant (ou de deux étudiants) en L3 Mathématiques, pour les deux semestres de l'année universitaire.\n",
    "\n",
    "On vous fournit les ECUE, leurs coefficients, et les notes (aléatoires) de chaque étudiant.\n",
    "\n",
    "\n",
    "### Semestre 1\n",
    "\n",
    "- Créér une **Series** contenant les coefficients des ECUE. Les indices doivent être les noms des ECUE.\n",
    "- Crééer une **Series** contenant les notes des ECUE (entiers aléatoires entre 0 et 20), avec les mêmes indices que pour les coefficients.\n",
    "- Construire un **DataFrame** à partir de ces deux Series.\n",
    "\n",
    "Exemple attendu :   \n",
    "![](L3_S1.png) \n",
    "\n",
    "Bonus: ajouter un deuxième étudiant.\n",
    "\n",
    "\n",
    "### Semestre 2\n",
    "\n",
    "Faire la même chose pour les ECUE du semestre 2.\n",
    "\n",
    "Exemple attendu :  \n",
    "![](L3_S2.png)\n",
    "\n",
    "Bonus: ajouter un deuxième étudiant.\n",
    "\n",
    "\n",
    "### Calculs à effectuer à partir des deux DataFrames \n",
    "\n",
    "- Calculer la **moyenne pondérée** du semestre 1 :\n",
    "$$\n",
    "\\bar{x} = \\frac{\\sum_i \\text{note}_i \\times \\text{coeff}_i}{\\sum_i \\text{coeff}_i}\n",
    "$$\n",
    "- Calculer la **moyenne pondérée** du semestre 2\n",
    "- Fusionner les deux DataFrames (par concaténation) puis calculer la moyenne pondérée globale. Exemple attendu :  \n",
    "![](L3.png)\n",
    "\n",
    "\n",
    "- Pour chaque étudiant, déterminer l'ECUE où il a eu sa pire note et l'ECUE où il a eu sa meilleure note. \n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-30T13:10:51.759790Z",
     "iopub.status.busy": "2026-10-30T13:10:51.759075Z",
     "iopub.status.idle": "2026-10-30T13:10:52.094610Z",
     "shell.execute_reply": "2026-10-30T13:10:52.093664Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "# Graine fixée : les notes sont tirées au hasard, mais on veut que le\n",
    "# notebook donne le même résultat à chaque exécution.\n",
    "np.random.seed(0)\n",
    "\n",
    "from IPython.display import display, Markdown"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-30T13:10:52.098016Z",
     "iopub.status.busy": "2026-10-30T13:10:52.097646Z",
     "iopub.status.idle": "2026-10-30T13:10:52.114674Z",
     "shell.execute_reply": "2026-10-30T13:10:52.113935Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Coefficients</th>\n",
       "      <th>Étudiant 1</th>\n",
       "      <th>Étudiant 2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>M51 Intégration</th>\n",
       "      <td>8</td>\n",
       "      <td>12</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M52 Topologie</th>\n",
       "      <td>8</td>\n",
       "      <td>15</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M53 Calcul différentiel</th>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M54 Algèbre 5</th>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M55 DS&amp;SC 5</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RDOC</th>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PPE</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         Coefficients  Étudiant 1  Étudiant 2\n",
       "M51 Intégration                     8          12          19\n",
       "M52 Topologie                       8          15          18\n",
       "M53 Calcul différentiel             8           0           4\n",
       "M54 Algèbre 5                       4           3           6\n",
       "M55 DS&SC 5                         2           3          12\n",
       "RDOC                                0           7           1\n",
       "PPE                                 0           9           6"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# --- Semestre 1 : définition des ECUE, coefficients, et notes des étudiants ---\n",
    "\n",
    "# Liste des ECUE du semestre 1\n",
    "ecue_names_semester1 = [\n",
    "    \"M51 Intégration\",\n",
    "    \"M52 Topologie\",\n",
    "    \"M53 Calcul différentiel\",\n",
    "    \"M54 Algèbre 5\",\n",
    "    \"M55 DS&SC 5\",\n",
    "    \"RDOC\",\n",
    "    \"PPE\"\n",
    "]\n",
    "\n",
    "nb_ecue_semester1 = len(ecue_names_semester1)\n",
    "\n",
    "# Coefficients des ECUE (indexés par les noms des ECUE)\n",
    "coefficients_semester1 = pd.Series(\n",
    "    [8, 8, 8, 4, 2, 0, 0],\n",
    "    index=ecue_names_semester1\n",
    ")\n",
    "\n",
    "# Notes aléatoires pour deux étudiants\n",
    "etu_1_semester1 = pd.Series(\n",
    "    np.random.randint(0, 21, size=nb_ecue_semester1),\n",
    "    index=ecue_names_semester1\n",
    ")\n",
    "\n",
    "etu_2_semester1 = pd.Series(\n",
    "    np.random.randint(0, 21, size=nb_ecue_semester1),\n",
    "    index=ecue_names_semester1\n",
    ")\n",
    "\n",
    "# Construction du DataFrame\n",
    "df_semester1 = pd.DataFrame({\n",
    "    \"Coefficients\": coefficients_semester1,\n",
    "    \"Étudiant 1\": etu_1_semester1,\n",
    "    \"Étudiant 2\": etu_2_semester1\n",
    "})\n",
    "\n",
    "display(df_semester1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-30T13:10:52.152601Z",
     "iopub.status.busy": "2026-10-30T13:10:52.152420Z",
     "iopub.status.idle": "2026-10-30T13:10:52.159639Z",
     "shell.execute_reply": "2026-10-30T13:10:52.159027Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Coefficients</th>\n",
       "      <th>Étudiant 1</th>\n",
       "      <th>Étudiant 2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>M61 EDO</th>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M62 Analyse Complexe</th>\n",
       "      <td>9</td>\n",
       "      <td>14</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M63 Modélisation</th>\n",
       "      <td>4</td>\n",
       "      <td>17</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M64 DS&amp;SC 6</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UE65</th>\n",
       "      <td>6</td>\n",
       "      <td>13</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UE66</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      Coefficients  Étudiant 1  Étudiant 2\n",
       "M61 EDO                          5           7           9\n",
       "M62 Analyse Complexe             9          14          20\n",
       "M63 Modélisation                 4          17          19\n",
       "M64 DS&SC 6                      4           5          16\n",
       "UE65                             6          13          19\n",
       "UE66                             2           8           5"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# --- Semestre 2 : définition des ECUE, coefficients, et notes des étudiants ---\n",
    "\n",
    "# Liste des ECUE du semestre 2\n",
    "ecue_names_semester2 = [\n",
    "    \"M61 EDO\",\n",
    "    \"M62 Analyse Complexe\",\n",
    "    \"M63 Modélisation\",\n",
    "    \"M64 DS&SC 6\",\n",
    "    \"UE65\",\n",
    "    \"UE66\"\n",
    "]\n",
    "\n",
    "nb_ecue_semester2 = len(ecue_names_semester2)\n",
    "\n",
    "# Coefficients des ECUE (indexés par les noms des ECUE)\n",
    "coefficients_semester2 = pd.Series(\n",
    "    [5, 9, 4, 4, 6, 2],\n",
    "    index=ecue_names_semester2\n",
    ")\n",
    "\n",
    "# Notes aléatoires pour deux étudiants\n",
    "etu_1_semester2 = pd.Series(\n",
    "    np.random.randint(0, 21, size=nb_ecue_semester2),\n",
    "    index=ecue_names_semester2\n",
    ")\n",
    "\n",
    "etu_2_semester2 = pd.Series(\n",
    "    np.random.randint(0, 21, size=nb_ecue_semester2),\n",
    "    index=ecue_names_semester2\n",
    ")\n",
    "\n",
    "# Construction du DataFrame\n",
    "df_semester2 = pd.DataFrame({\n",
    "    \"Coefficients\": coefficients_semester2,\n",
    "    \"Étudiant 1\": etu_1_semester2,\n",
    "    \"Étudiant 2\": etu_2_semester2\n",
    "})\n",
    "\n",
    "display(df_semester2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-30T13:10:52.161441Z",
     "iopub.status.busy": "2026-10-30T13:10:52.161288Z",
     "iopub.status.idle": "2026-10-30T13:10:52.163755Z",
     "shell.execute_reply": "2026-10-30T13:10:52.163224Z"
    }
   },
   "outputs": [],
   "source": [
    "# Calcul de la moyenne pondérée pour un étudiant donné au semestre 1\n",
    "\n",
    "# df_semester1[\"Étudiant 1\"].mean()  \n",
    "# Non pertinent : cette moyenne n'est pas pondérée, \n",
    "# donc elle donne le même poids à un ECUE coefficient 8 qu'à un ECUE coefficient 0."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-30T13:10:52.165430Z",
     "iopub.status.busy": "2026-10-30T13:10:52.165282Z",
     "iopub.status.idle": "2026-10-30T13:10:52.168112Z",
     "shell.execute_reply": "2026-10-30T13:10:52.167615Z"
    }
   },
   "outputs": [],
   "source": [
    "# Fonction qui pour un DataFrame donné et un étudiant donné \n",
    "# calcule la moyenne pondérée\n",
    "\n",
    "def weighted_average(df, student_name):\n",
    "    notes = df[student_name]\n",
    "    coeffs = df[\"Coefficients\"]\n",
    "    \n",
    "    # --- Somme pondérée ---\n",
    "    return (notes * coeffs).sum() / coeffs.sum()\n",
    "    \n",
    "    # --- Alternatives  ---\n",
    "    # return notes.dot(coeffs) / coeffs.sum()\n",
    "    # return np.average(notes, weights=coeffs)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-30T13:10:52.170026Z",
     "iopub.status.busy": "2026-10-30T13:10:52.169854Z",
     "iopub.status.idle": "2026-10-30T13:10:52.173847Z",
     "shell.execute_reply": "2026-10-30T13:10:52.173307Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Semestre 1\n",
      "Étudiant 1 : 7.80\n",
      "Étudiant 2 : 12.53\n"
     ]
    }
   ],
   "source": [
    "# Moyenne pondérée pour chaque étudiant au semestre 1\n",
    "print(\"Semestre 1\")\n",
    "for etu in [\"Étudiant 1\", \"Étudiant 2\"]:\n",
    "    print(f\"{etu} : {weighted_average(df_semester1, etu):.2f}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-30T13:10:52.175596Z",
     "iopub.status.busy": "2026-10-30T13:10:52.175356Z",
     "iopub.status.idle": "2026-10-30T13:10:52.179252Z",
     "shell.execute_reply": "2026-10-30T13:10:52.178791Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Semestre 2\n",
      "Étudiant 1 : 11.43\n",
      "Étudiant 2 : 16.30\n"
     ]
    }
   ],
   "source": [
    "# Moyenne pondérée pour chaque étudiant au semestre 2\n",
    "print(\"Semestre 2\")\n",
    "for etu in [\"Étudiant 1\", \"Étudiant 2\"]:\n",
    "    print(f\"{etu} : {weighted_average(df_semester2, etu):.2f}\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Notes et coefficients pour l'année entière :"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-30T13:10:52.180956Z",
     "iopub.status.busy": "2026-10-30T13:10:52.180804Z",
     "iopub.status.idle": "2026-10-30T13:10:52.186731Z",
     "shell.execute_reply": "2026-10-30T13:10:52.186253Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Coefficients</th>\n",
       "      <th>Étudiant 1</th>\n",
       "      <th>Étudiant 2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>M51 Intégration</th>\n",
       "      <td>8</td>\n",
       "      <td>12</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M52 Topologie</th>\n",
       "      <td>8</td>\n",
       "      <td>15</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M53 Calcul différentiel</th>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M54 Algèbre 5</th>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M55 DS&amp;SC 5</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RDOC</th>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PPE</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M61 EDO</th>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M62 Analyse Complexe</th>\n",
       "      <td>9</td>\n",
       "      <td>14</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M63 Modélisation</th>\n",
       "      <td>4</td>\n",
       "      <td>17</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M64 DS&amp;SC 6</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UE65</th>\n",
       "      <td>6</td>\n",
       "      <td>13</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UE66</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         Coefficients  Étudiant 1  Étudiant 2\n",
       "M51 Intégration                     8          12          19\n",
       "M52 Topologie                       8          15          18\n",
       "M53 Calcul différentiel             8           0           4\n",
       "M54 Algèbre 5                       4           3           6\n",
       "M55 DS&SC 5                         2           3          12\n",
       "RDOC                                0           7           1\n",
       "PPE                                 0           9           6\n",
       "M61 EDO                             5           7           9\n",
       "M62 Analyse Complexe                9          14          20\n",
       "M63 Modélisation                    4          17          19\n",
       "M64 DS&SC 6                         4           5          16\n",
       "UE65                                6          13          19\n",
       "UE66                                2           8           5"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# ==========================================\n",
    "# Fusion des semestres pour l'année entière\n",
    "# ==========================================\n",
    "\n",
    "# Option 1 : concaténation simple (les lignes sont juste empilées)\n",
    "df_year = pd.concat([df_semester1, df_semester2])\n",
    "display(df_year)\n",
    "\n",
    "# Option 2 : concaténation avec MultiIndex pour identifier le semestre\n",
    "# df_year = pd.concat([df_semester1, df_semester2], \n",
    "#                     keys=[\"Semestre 1\", \"Semestre 2\"], axis=0)\n",
    "# display(df_year)\n",
    "\n",
    "# Avantages :\n",
    "# - Option 1 : plus simple pour calculer directement les moyennes pondérées\n",
    "# - Option 2 : permet de conserver l'information du semestre dans l'index\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-30T13:10:52.188509Z",
     "iopub.status.busy": "2026-10-30T13:10:52.188330Z",
     "iopub.status.idle": "2026-10-30T13:10:52.192380Z",
     "shell.execute_reply": "2026-10-30T13:10:52.192023Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Étudiant 1 :\n",
      "  Pire note au semestre 1 : 0 à M53 Calcul différentiel\n",
      "  Meilleure note au semestre 1 : 15 à M52 Topologie\n",
      "\n",
      "Étudiant 2 :\n",
      "  Pire note au semestre 1 : 1 à RDOC\n",
      "  Meilleure note au semestre 1 : 19 à M51 Intégration\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Calculs de la pire et meilleure note pour chaque étudiant au semestre 1 \n",
    "\n",
    "for etu in [\"Étudiant 1\", \"Étudiant 2\"]:\n",
    "    min_idx = df_semester1[etu].idxmin()\n",
    "    max_idx = df_semester1[etu].idxmax()\n",
    "    print(f\"{etu} :\")\n",
    "    print(f\"  Pire note au semestre 1 : {df_semester1.loc[min_idx, etu]} à {min_idx}\")\n",
    "    print(f\"  Meilleure note au semestre 1 : {df_semester1.loc[max_idx, etu]} à {max_idx}\")\n",
    "    print()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-30T13:10:52.194061Z",
     "iopub.status.busy": "2026-10-30T13:10:52.193897Z",
     "iopub.status.idle": "2026-10-30T13:10:52.201471Z",
     "shell.execute_reply": "2026-10-30T13:10:52.200964Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Étudiant 1</th>\n",
       "      <th>Étudiant 2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Pire note</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ECUE pire note</th>\n",
       "      <td>M53 Calcul différentiel</td>\n",
       "      <td>RDOC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Meilleure note</th>\n",
       "      <td>17</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ECUE meilleure note</th>\n",
       "      <td>M63 Modélisation</td>\n",
       "      <td>M62 Analyse Complexe</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Moyenne annuelle pondérée</th>\n",
       "      <td>9.616667</td>\n",
       "      <td>14.416667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Moyenne semestre 1</th>\n",
       "      <td>7.8</td>\n",
       "      <td>12.533333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Moyenne semestre 2</th>\n",
       "      <td>11.433333</td>\n",
       "      <td>16.3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        Étudiant 1            Étudiant 2\n",
       "Pire note                                        0                     1\n",
       "ECUE pire note             M53 Calcul différentiel                  RDOC\n",
       "Meilleure note                                  17                    20\n",
       "ECUE meilleure note               M63 Modélisation  M62 Analyse Complexe\n",
       "Moyenne annuelle pondérée                 9.616667             14.416667\n",
       "Moyenne semestre 1                             7.8             12.533333\n",
       "Moyenne semestre 2                       11.433333                  16.3"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# ===============================\n",
    "# DataFrame récapitulatif annuel\n",
    "# ===============================\n",
    "\n",
    "students = [\"Étudiant 1\", \"Étudiant 2\"]\n",
    "\n",
    "df_summary = pd.DataFrame({\n",
    "    etu: {\n",
    "        \"Pire note\": df_year[etu].min(),\n",
    "        \"ECUE pire note\": df_year[etu].idxmin(),\n",
    "        \"Meilleure note\": df_year[etu].max(),\n",
    "        \"ECUE meilleure note\": df_year[etu].idxmax(),\n",
    "        \"Moyenne annuelle pondérée\": weighted_average(df_year, etu),\n",
    "        \"Moyenne semestre 1\": weighted_average(df_semester1, etu),\n",
    "        \"Moyenne semestre 2\": weighted_average(df_semester2, etu)\n",
    "    } \n",
    "    for etu in students\n",
    "})\n",
    "\n",
    "display(df_summary)\n"
   ]
  },
  {
   "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.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
