{ "cells": [ { "cell_type": "code", "execution_count": 87, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pandas as pd\n", "from texenv import texenv\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 88, "metadata": { "collapsed": false }, "outputs": [], "source": [ "notes = pd.read_excel(\"./../../../notes_1stmg.xls\",sheetname=\"DS_0320\")" ] }, { "cell_type": "code", "execution_count": 89, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Index(['DS_0320', 'av_arrondi', 'Exercice 1', '1 (double inclusion)', '2 (double inclusion)', '3 (proportion)', 'Exercice 2', '1 (Remplir tableau)', '2.a (calculer proportion)', '2.b (calculer proportion)', '2.c (proportion parmi)', '2.d (proportion parmi)', 'Exercice 3', '1 (completer arbre)', '2.a (proportion feuille)', '2.b (proportion feuille)', '2.c (proportion ou)', '3 (calculer quantité)', 'Exercice 4', '1 (tracer fonction)', '2 (maximum)'], dtype='object')" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "source": [ "notes.index" ] }, { "cell_type": "code", "execution_count": 90, "metadata": { "collapsed": true }, "outputs": [], "source": [ "notes = notes.T" ] }, { "cell_type": "code", "execution_count": 91, "metadata": { "collapsed": false }, "outputs": [], "source": [ "notes = notes.drop(\"av_arrondi\", axis=1)" ] }, { "cell_type": "code", "execution_count": 92, "metadata": { "collapsed": false }, "outputs": [], "source": [ "barem = notes[:1]\n", "notes = notes[1:]" ] }, { "cell_type": "code", "execution_count": 93, "metadata": { "collapsed": false }, "outputs": [], "source": [ "notes = notes[notes[\"DS_0320\"].notnull()]" ] }, { "cell_type": "code", "execution_count": 94, "metadata": { "collapsed": false }, "outputs": [ { "ename": "ValueError", "evalue": "could not convert string to float: ", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mnotes\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnotes\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;32m/home/lafrite/.virtualenvs/data_analysis/lib/python3.4/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36mastype\u001b[1;34m(self, dtype, copy, raise_on_error)\u001b[0m\n\u001b[0;32m 2212\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2213\u001b[0m mgr = self._data.astype(\n\u001b[1;32m-> 2214\u001b[1;33m dtype=dtype, copy=copy, raise_on_error=raise_on_error)\n\u001b[0m\u001b[0;32m 2215\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_constructor\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmgr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__finalize__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2216\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m/home/lafrite/.virtualenvs/data_analysis/lib/python3.4/site-packages/pandas/core/internals.py\u001b[0m in \u001b[0;36mastype\u001b[1;34m(self, dtype, **kwargs)\u001b[0m\n\u001b[0;32m 2500\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2501\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2502\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'astype'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2503\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2504\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mconvert\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m/home/lafrite/.virtualenvs/data_analysis/lib/python3.4/site-packages/pandas/core/internals.py\u001b[0m in \u001b[0;36mapply\u001b[1;34m(self, f, axes, filter, do_integrity_check, **kwargs)\u001b[0m\n\u001b[0;32m 2455\u001b[0m copy=align_copy)\n\u001b[0;32m 2456\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2457\u001b[1;33m \u001b[0mapplied\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2458\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2459\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mapplied\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlist\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m/home/lafrite/.virtualenvs/data_analysis/lib/python3.4/site-packages/pandas/core/internals.py\u001b[0m in \u001b[0;36mastype\u001b[1;34m(self, dtype, copy, raise_on_error, values)\u001b[0m\n\u001b[0;32m 369\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mraise_on_error\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalues\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 370\u001b[0m return self._astype(dtype, copy=copy, raise_on_error=raise_on_error,\n\u001b[1;32m--> 371\u001b[1;33m values=values)\n\u001b[0m\u001b[0;32m 372\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 373\u001b[0m def _astype(self, dtype, copy=False, raise_on_error=True, values=None,\n", "\u001b[1;32m/home/lafrite/.virtualenvs/data_analysis/lib/python3.4/site-packages/pandas/core/internals.py\u001b[0m in \u001b[0;36m_astype\u001b[1;34m(self, dtype, copy, raise_on_error, values, klass)\u001b[0m\n\u001b[0;32m 399\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mvalues\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 400\u001b[0m \u001b[1;31m# _astype_nansafe works fine with 1-d only\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 401\u001b[1;33m \u001b[0mvalues\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_astype_nansafe\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mravel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 402\u001b[0m \u001b[0mvalues\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvalues\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 403\u001b[0m newb = make_block(values,\n", "\u001b[1;32m/home/lafrite/.virtualenvs/data_analysis/lib/python3.4/site-packages/pandas/core/common.py\u001b[0m in \u001b[0;36m_astype_nansafe\u001b[1;34m(arr, dtype, copy)\u001b[0m\n\u001b[0;32m 2627\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2628\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2629\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0marr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2630\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0marr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mview\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2631\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mValueError\u001b[0m: could not convert string to float: " ] } ], "source": [ "notes = notes.astype(float)" ] }, { "cell_type": "code", "execution_count": 95, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "count 31\n", "unique 18\n", "top 11\n", "freq 5\n", "Name: DS_0320, dtype: float64" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "notes['DS_0320'].describe()" ] }, { "cell_type": "code", "execution_count": 96, "metadata": { "collapsed": false }, "outputs": [], "source": [ "list_exo = [\"Exercice 1\", \"Exercice 2\", \"Exercice 3\", \"Exercice 4\"]" ] }, { "cell_type": "code", "execution_count": 97, "metadata": { "collapsed": false }, "outputs": [], "source": [ "notes[list_exo] = notes[list_exo].applymap(lambda x:round(x,2))" ] }, { "cell_type": "code", "execution_count": 98, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def toRepVal(val):\n", " if pd.isnull(val):\n", " return \"\\\\NoRep\"\n", " elif val == 0:\n", " return \"\\\\RepZ\"\n", " elif val == 1:\n", " return \"\\\\RepU\"\n", " elif val == 2:\n", " return \"\\\\RepD\"\n", " elif val == 3:\n", " return \"\\\\RepT\"\n", " else:\n", " return val" ] }, { "cell_type": "code", "execution_count": 99, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "['1 (double inclusion)',\n", " '2 (double inclusion)',\n", " '3 (proportion)',\n", " '1 (Remplir tableau)',\n", " '2.a (calculer proportion)',\n", " '2.b (calculer proportion)',\n", " '2.c (proportion parmi)',\n", " '2.d (proportion parmi)',\n", " '1 (completer arbre)',\n", " '2.a (proportion feuille)',\n", " '2.b (proportion feuille)',\n", " '2.c (proportion ou)',\n", " '3 (calculer quantité)',\n", " '1 (tracer fonction)',\n", " '2 (maximum)']" ] }, "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sous_exo = [i for i in notes.T.index if i not in list_exo + ['DS_0320']]\n", "sous_exo" ] }, { "cell_type": "code", "execution_count": 100, "metadata": { "collapsed": false }, "outputs": [], "source": [ "notes[sous_exo] = notes[sous_exo].applymap(toRepVal)" ] }, { "cell_type": "code", "execution_count": 101, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Index(['DS_0320', 'Exercice 1', '1 (double inclusion)', '2 (double inclusion)', '3 (proportion)', 'Exercice 2', '1 (Remplir tableau)', '2.a (calculer proportion)', '2.b (calculer proportion)', '2.c (proportion parmi)', '2.d (proportion parmi)', 'Exercice 3', '1 (completer arbre)', '2.a (proportion feuille)', '2.b (proportion feuille)', '2.c (proportion ou)', '3 (calculer quantité)', 'Exercice 4', '1 (tracer fonction)', '2 (maximum)'], dtype='object')" ] }, "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [ "notes.T.index" ] }, { "cell_type": "code", "execution_count": 102, "metadata": { "collapsed": false }, "outputs": [], "source": [ "bilan = texenv.get_template(\"tpl_bilan.tex\")\n", "with open(\"./bilan.tex\",\"w\") as f:\n", " f.write(bilan.render(eleves = notes, barem = barem))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "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.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }