Tentative de faire un tableau avec pygal (fail...)

This commit is contained in:
Bertrand Benjamin 2017-09-22 07:27:27 +03:00
parent 59d178f649
commit 8fe35b6c38

View File

@ -719,7 +719,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -731,7 +731,7 @@
" dtype='object')" " dtype='object')"
] ]
}, },
"execution_count": 21, "execution_count": 10,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -742,8 +742,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": 11,
"metadata": { "metadata": {
"collapsed": true,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -753,8 +754,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 26, "execution_count": 12,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"dnb2017_ville = dnb2017_ville.assign(\n", "dnb2017_ville = dnb2017_ville.assign(\n",
@ -764,8 +767,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": 13,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"dnb2017_ville = dnb2017_ville.assign(\n", "dnb2017_ville = dnb2017_ville.assign(\n",
@ -777,8 +782,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": 14,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"dnb2017_ville = dnb2017_ville.reset_index()" "dnb2017_ville = dnb2017_ville.reset_index()"
@ -786,7 +793,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 68, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -1045,7 +1052,7 @@
"13 36.000000 " "13 36.000000 "
] ]
}, },
"execution_count": 68, "execution_count": 15,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -1056,7 +1063,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 65, "execution_count": 16,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -1088,7 +1095,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 66, "execution_count": 17,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -1100,7 +1107,7 @@
" dtype='object')" " dtype='object')"
] ]
}, },
"execution_count": 66, "execution_count": 17,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -1142,7 +1149,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 18,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -1179,6 +1186,257 @@
"#bar_chart.render_to_file(f\"./fig/bar_admis_clg.svg\")" "#bar_chart.render_to_file(f\"./fig/bar_admis_clg.svg\")"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Tableau des colleges avec le plus de mentions"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Collège</th>\n",
" <th>Ville</th>\n",
" <th>Présents\n",
"au DNB</th>\n",
" <th>Taux de réussite</th>\n",
" <th>Taux de mentions</th>\n",
" <th>tx_admis</th>\n",
" <th>tx_mention</th>\n",
" <th>nbr_admis</th>\n",
" <th>nbr_mentions</th>\n",
" <th>nbr_sans_mentions</th>\n",
" <th>tx_non_admis</th>\n",
" <th>tx_sans_mention</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>SADA</td>\n",
" <td>Sada</td>\n",
" <td>229</td>\n",
" <td>81.66 %</td>\n",
" <td>49.78 %</td>\n",
" <td>0.8166</td>\n",
" <td>0.4978</td>\n",
" <td>187</td>\n",
" <td>113</td>\n",
" <td>74</td>\n",
" <td>0.1834</td>\n",
" <td>0.3188</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>KANI-KELI</td>\n",
" <td>Kani keli</td>\n",
" <td>158</td>\n",
" <td>85.44 %</td>\n",
" <td>48.10 %</td>\n",
" <td>0.8544</td>\n",
" <td>0.4810</td>\n",
" <td>134</td>\n",
" <td>75</td>\n",
" <td>59</td>\n",
" <td>0.1456</td>\n",
" <td>0.3734</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>BANDRELE</td>\n",
" <td>Bandrele</td>\n",
" <td>176</td>\n",
" <td>78.41 %</td>\n",
" <td>47.73 %</td>\n",
" <td>0.7841</td>\n",
" <td>0.4773</td>\n",
" <td>138</td>\n",
" <td>84</td>\n",
" <td>54</td>\n",
" <td>0.2159</td>\n",
" <td>0.3068</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>PASSAMAINTY</td>\n",
" <td>Mamoudzou</td>\n",
" <td>344</td>\n",
" <td>87.21 %</td>\n",
" <td>47.67 %</td>\n",
" <td>0.8721</td>\n",
" <td>0.4767</td>\n",
" <td>300</td>\n",
" <td>163</td>\n",
" <td>137</td>\n",
" <td>0.1279</td>\n",
" <td>0.3954</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>KAWENI 1</td>\n",
" <td>Mamoudzou</td>\n",
" <td>333</td>\n",
" <td>86.79 %</td>\n",
" <td>47.15 %</td>\n",
" <td>0.8679</td>\n",
" <td>0.4715</td>\n",
" <td>289</td>\n",
" <td>157</td>\n",
" <td>132</td>\n",
" <td>0.1321</td>\n",
" <td>0.3964</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Collège Ville Présents\\nau DNB Taux de réussite Taux de mentions \\\n",
"0 SADA Sada 229 81.66 % 49.78 % \n",
"1 KANI-KELI Kani keli 158 85.44 % 48.10 % \n",
"2 BANDRELE Bandrele 176 78.41 % 47.73 % \n",
"3 PASSAMAINTY Mamoudzou 344 87.21 % 47.67 % \n",
"4 KAWENI 1 Mamoudzou 333 86.79 % 47.15 % \n",
"\n",
" tx_admis tx_mention nbr_admis nbr_mentions nbr_sans_mentions \\\n",
"0 0.8166 0.4978 187 113 74 \n",
"1 0.8544 0.4810 134 75 59 \n",
"2 0.7841 0.4773 138 84 54 \n",
"3 0.8721 0.4767 300 163 137 \n",
"4 0.8679 0.4715 289 157 132 \n",
"\n",
" tx_non_admis tx_sans_mention \n",
"0 0.1834 0.3188 \n",
"1 0.1456 0.3734 \n",
"2 0.2159 0.3068 \n",
"3 0.1279 0.3954 \n",
"4 0.1321 0.3964 "
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dnb2017.head()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"top_mentions = dnb2017[['Collège', 'nbr_mentions']].sort_values('nbr_mentions',ascending=False).head(3)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Collège</th>\n",
" <th>nbr_mentions</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>NELSON MANDELA</td>\n",
" <td>166</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>PASSAMAINTY</td>\n",
" <td>163</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>KAWENI 1</td>\n",
" <td>157</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Collège nbr_mentions\n",
"9 NELSON MANDELA 166\n",
"3 PASSAMAINTY 163\n",
"4 KAWENI 1 157"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"top_mentions"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"line_chart = pygal.Bar()\n",
"line_chart.title = 'Top 3 du nombre de mentions'\n",
"line_chart.x_labels = top_mentions['Collège']\n",
"line_chart.add('Nombre de mentions', top_mentions['nbr_mentions'])\n",
"with open(\"./fig/top3mentions.svg\", \"w\") as f:\n",
" f.write(line_chart.render_table(style=True))"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,