{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Création des données pour le chapitre" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'fr_FR.UTF-8'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import Markdown as md\n", "from IPython.display import display, HTML\n", "import pandas as pd\n", "import ipywidgets as widgets\n", "from pathlib import Path\n", "from datetime import datetime\n", "import locale\n", "locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Les données viennent de https://github.com/chris1610/pbpython/blob/master/data/2018_Sales_Total.xlsx" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "df = pd.read_excel('2018_Sales_Total.xlsx')\n", "df = df.rename(columns={\"Nom\": \"Vendeur\"})" ] }, { "cell_type": "code", "execution_count": 3, "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", "
Numero de compteVendeurCodePrixdateProduit
0740150Barton LLCB1-2000086.692018-01-01 07:21:51Logiciel
1714466Trantow-BarrowsS2-7789663.162018-01-01 10:00:47Ordinateur
2218895Kulas IncB1-6992490.702018-01-01 13:24:58Logiciel
3307599Kassulke, Ondricka and MetzS1-6548121.052018-01-01 15:05:22Impression
4412290Jerde-HilpertS2-3407783.212018-01-01 23:26:55Ordinateur
\n", "
" ], "text/plain": [ " Numero de compte Vendeur Code Prix \\\n", "0 740150 Barton LLC B1-20000 86.69 \n", "1 714466 Trantow-Barrows S2-77896 63.16 \n", "2 218895 Kulas Inc B1-69924 90.70 \n", "3 307599 Kassulke, Ondricka and Metz S1-65481 21.05 \n", "4 412290 Jerde-Hilpert S2-34077 83.21 \n", "\n", " date Produit \n", "0 2018-01-01 07:21:51 Logiciel \n", "1 2018-01-01 10:00:47 Ordinateur \n", "2 2018-01-01 13:24:58 Logiciel \n", "3 2018-01-01 15:05:22 Impression \n", "4 2018-01-01 23:26:55 Ordinateur " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Réduction des codes produits avec un type de produit" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['B1-20000', 'S2-77896', 'B1-69924', 'S1-65481', 'S2-34077',\n", " 'B1-65551', 'S1-30248', 'S1-50961', 'S2-82423', 'S2-00301',\n", " 'S2-23246', 'S2-10342', 'B1-53102', 'S1-06532', 'B1-50809',\n", " 'S1-82801', 'B1-04202', 'S2-83881', 'S2-78676', 'B1-53636',\n", " 'B1-38851', 'B1-86481', 'S1-93683', 'B1-33087', 'S1-27722',\n", " 'B1-05914', 'B1-33364', 'S2-16558', 'S1-47412', 'S2-11481'],\n", " dtype=object)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.Code.unique()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['B1', 'S2', 'S1'], dtype=object)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.apply(lambda x: x.Code[:2], axis=1).unique()" ] }, { "cell_type": "code", "execution_count": 6, "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", "
Numero de compteVendeurCodePrixdateProduit
0740150Barton LLCB1-2000086.692018-01-01 07:21:51Logiciel
1714466Trantow-BarrowsS2-7789663.162018-01-01 10:00:47Ordinateur
2218895Kulas IncB1-6992490.702018-01-01 13:24:58Logiciel
3307599Kassulke, Ondricka and MetzS1-6548121.052018-01-01 15:05:22Impression
4412290Jerde-HilpertS2-3407783.212018-01-01 23:26:55Ordinateur
\n", "
" ], "text/plain": [ " Numero de compte Vendeur Code Prix \\\n", "0 740150 Barton LLC B1-20000 86.69 \n", "1 714466 Trantow-Barrows S2-77896 63.16 \n", "2 218895 Kulas Inc B1-69924 90.70 \n", "3 307599 Kassulke, Ondricka and Metz S1-65481 21.05 \n", "4 412290 Jerde-Hilpert S2-34077 83.21 \n", "\n", " date Produit \n", "0 2018-01-01 07:21:51 Logiciel \n", "1 2018-01-01 10:00:47 Ordinateur \n", "2 2018-01-01 13:24:58 Logiciel \n", "3 2018-01-01 15:05:22 Impression \n", "4 2018-01-01 23:26:55 Ordinateur " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "code_prod = {\n", " \"B1\": \"Logiciel\",\n", " \"S1\": \"Impression\",\n", " \"S2\": \"Ordinateur\"\n", "}\n", "df[\"Produit\"] = df.apply(lambda x: code_prod[x.Code[:2]], axis=1)\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Réduction du nombre de noms" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['Barton LLC', 'Trantow-Barrows', 'Kulas Inc',\n", " 'Kassulke, Ondricka and Metz', 'Jerde-Hilpert'], dtype=object)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uniq_names = df.Vendeur.unique()\n", "uniq_names" ] }, { "cell_type": "code", "execution_count": 8, "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", "
Numero de compteVendeurCodePrixdateProduit
0740150Barton LLCB1-2000086.692018-01-01 07:21:51Logiciel
1714466Trantow-BarrowsS2-7789663.162018-01-01 10:00:47Ordinateur
2218895Kulas IncB1-6992490.702018-01-01 13:24:58Logiciel
3307599Kassulke, Ondricka and MetzS1-6548121.052018-01-01 15:05:22Impression
4412290Jerde-HilpertS2-3407783.212018-01-01 23:26:55Ordinateur
\n", "
" ], "text/plain": [ " Numero de compte Vendeur Code Prix \\\n", "0 740150 Barton LLC B1-20000 86.69 \n", "1 714466 Trantow-Barrows S2-77896 63.16 \n", "2 218895 Kulas Inc B1-69924 90.70 \n", "3 307599 Kassulke, Ondricka and Metz S1-65481 21.05 \n", "4 412290 Jerde-Hilpert S2-34077 83.21 \n", "\n", " date Produit \n", "0 2018-01-01 07:21:51 Logiciel \n", "1 2018-01-01 10:00:47 Ordinateur \n", "2 2018-01-01 13:24:58 Logiciel \n", "3 2018-01-01 15:05:22 Impression \n", "4 2018-01-01 23:26:55 Ordinateur " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nbr_names = 5\n", "names = {orig: uniq_names[i%nbr_names] for (i, orig) in enumerate(uniq_names)}\n", "names\n", "df[\"Vendeur\"] = df.apply(lambda x: names[x.Vendeur], axis=1)\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 1500 entries, 0 to 1499\n", "Data columns (total 6 columns):\n", "Numero de compte 1500 non-null int64\n", "Vendeur 1500 non-null object\n", "Code 1500 non-null object\n", "Prix 1500 non-null float64\n", "date 1500 non-null datetime64[ns]\n", "Produit 1500 non-null object\n", "dtypes: datetime64[ns](1), float64(1), int64(1), object(3)\n", "memory usage: 70.4+ KB\n" ] } ], "source": [ "df.info()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "df.to_excel(\"2018_Sales_Total.xlsx\", index=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Données à traiter à la main - 10 premiers jours de janvier" ] }, { "cell_type": "code", "execution_count": 11, "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", "
Numero de compteVendeurCodePrixdateProduit
0740150Barton LLCB1-2000086.692018-01-01 07:21:51Logiciel
1714466Trantow-BarrowsS2-7789663.162018-01-01 10:00:47Ordinateur
2218895Kulas IncB1-6992490.702018-01-01 13:24:58Logiciel
3307599Kassulke, Ondricka and MetzS1-6548121.052018-01-01 15:05:22Impression
4412290Jerde-HilpertS2-3407783.212018-01-01 23:26:55Ordinateur
\n", "
" ], "text/plain": [ " Numero de compte Vendeur Code Prix \\\n", "0 740150 Barton LLC B1-20000 86.69 \n", "1 714466 Trantow-Barrows S2-77896 63.16 \n", "2 218895 Kulas Inc B1-69924 90.70 \n", "3 307599 Kassulke, Ondricka and Metz S1-65481 21.05 \n", "4 412290 Jerde-Hilpert S2-34077 83.21 \n", "\n", " date Produit \n", "0 2018-01-01 07:21:51 Logiciel \n", "1 2018-01-01 10:00:47 Ordinateur \n", "2 2018-01-01 13:24:58 Logiciel \n", "3 2018-01-01 15:05:22 Impression \n", "4 2018-01-01 23:26:55 Ordinateur " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hand_df = df.loc[df.date < \"2018-01-11\"]\n", "hand_df.head()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "hand_df.to_excel(\"201801_sales.xlsx\", index=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Quelques tableau d'effectifs et de fréquences" ] }, { "cell_type": "code", "execution_count": 124, "metadata": {}, "outputs": [], "source": [ "count = lambda x: x.count()\n", "count.__name__ = \"Effectif\"\n", "\n", "#freq = lambda x: f\"{x.count()/hand_df['Prix'].count():.2%}\"\n", "#freq.__name__ = \"Fréquence marginale\"\n", "\n", "def freq(total):\n", " func = lambda x: f\"{x.count()/total:.2%}\"\n", " func.__name__ = \"Fréquence marginale\"\n", " return func" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Par rapport aux vendeurs" ] }, { "cell_type": "code", "execution_count": 125, "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", "
EffectifFréquence marginale
Vendeur
Barton LLC819.51%
Jerde-Hilpert717.07%
Kassulke, Ondricka and Metz512.20%
Kulas Inc614.63%
Trantow-Barrows1536.59%
Total41100.00%
\n", "
" ], "text/plain": [ " Effectif Fréquence marginale\n", "Vendeur \n", "Barton LLC 8 19.51%\n", "Jerde-Hilpert 7 17.07%\n", "Kassulke, Ondricka and Metz 5 12.20%\n", "Kulas Inc 6 14.63%\n", "Trantow-Barrows 15 36.59%\n", "Total 41 100.00%" ] }, "execution_count": 125, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pt_sellers = pd.pivot_table(hand_df,\n", " index=\"Vendeur\",\n", " values=\"Code\",\n", " aggfunc=[count, freq(hand_df[\"Prix\"].count())],\n", " margins=True,\n", " margins_name=\"Total\")\n", "pt_sellers.columns = pt_sellers.columns.droplevel(1)\n", "pt_sellers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Par rapport aux Produits" ] }, { "cell_type": "code", "execution_count": 126, "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", "
EffectifFréquence marginale
Produit
Impression1229.27%
Logiciel1331.71%
Ordinateur1639.02%
Total41100.00%
\n", "
" ], "text/plain": [ " Effectif Fréquence marginale\n", "Produit \n", "Impression 12 29.27%\n", "Logiciel 13 31.71%\n", "Ordinateur 16 39.02%\n", "Total 41 100.00%" ] }, "execution_count": 126, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pt_sellers = pd.pivot_table(hand_df,\n", " index=\"Produit\",\n", " values=\"Code\",\n", " aggfunc=[count, freq(hand_df[\"Prix\"].count())],\n", " margins=True,\n", " margins_name=\"Total\"\n", " )\n", "pt_sellers.columns = pt_sellers.columns.droplevel(1)\n", "pt_sellers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Croisement de ventes entre vendeurs et produits" ] }, { "cell_type": "code", "execution_count": 37, "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", "
ProduitImpressionLogicielOrdinateurTotal
Vendeur
Barton LLC3.04.01.08
Jerde-Hilpert2.01.04.07
Kassulke, Ondricka and Metz1.0NaN4.05
Kulas Inc2.02.02.06
Trantow-Barrows4.06.05.015
Total12.013.016.041
\n", "
" ], "text/plain": [ "Produit Impression Logiciel Ordinateur Total\n", "Vendeur \n", "Barton LLC 3.0 4.0 1.0 8\n", "Jerde-Hilpert 2.0 1.0 4.0 7\n", "Kassulke, Ondricka and Metz 1.0 NaN 4.0 5\n", "Kulas Inc 2.0 2.0 2.0 6\n", "Trantow-Barrows 4.0 6.0 5.0 15\n", "Total 12.0 13.0 16.0 41" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.pivot_table(hand_df,\n", " index=\"Vendeur\",\n", " columns = \"Produit\",\n", " values=\"Code\",\n", " aggfunc=\"count\",\n", " margins=True,\n", " margins_name=\"Total\"\n", " )" ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "collapsed": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\\begin{tabular}{lrrrr}\n", "\\toprule\n", "\\textbf{Produit} & Impression & Logiciel & Ordinateur & Total \\\\\n", "\\textbf{Vendeur } & & & & \\\\\n", "\\midrule\n", "\\textbf{Barton LLC } & 3 & 4 & 1 & 8 \\\\\n", "\\textbf{Jerde-Hilpert } & 2 & 1 & 4 & 7 \\\\\n", "\\textbf{Kassulke, Ondricka and Metz} & 1 & nan & 4 & 5 \\\\\n", "\\textbf{Kulas Inc } & 2 & 2 & 2 & 6 \\\\\n", "\\textbf{Trantow-Barrows } & 4 & 6 & 5 & 15 \\\\\n", "\\textbf{Total } & 12 & 13 & 16 & 41 \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "source": [ "print(pd.pivot_table(hand_df,\n", " index=\"Vendeur\",\n", " columns = \"Produit\",\n", " values=\"Code\",\n", " aggfunc=\"count\",\n", " margins=True,\n", " margins_name=\"Total\"\n", " )\\\n", " .to_latex(\n", " float_format=\"{:0.0f}\".format,\n", " bold_rows=True\n", ")\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fréquences marginales" ] }, { "cell_type": "code", "execution_count": 127, "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", "
ProduitImpressionLogicielOrdinateurTotal
Vendeur
Barton LLC7.32%9.76%2.44%19.51%
Jerde-Hilpert4.88%2.44%9.76%17.07%
Kassulke, Ondricka and Metz2.44%NaN9.76%12.20%
Kulas Inc4.88%4.88%4.88%14.63%
Trantow-Barrows9.76%14.63%12.20%36.59%
Total29.27%31.71%39.02%100.00%
\n", "
" ], "text/plain": [ "Produit Impression Logiciel Ordinateur Total\n", "Vendeur \n", "Barton LLC 7.32% 9.76% 2.44% 19.51%\n", "Jerde-Hilpert 4.88% 2.44% 9.76% 17.07%\n", "Kassulke, Ondricka and Metz 2.44% NaN 9.76% 12.20%\n", "Kulas Inc 4.88% 4.88% 4.88% 14.63%\n", "Trantow-Barrows 9.76% 14.63% 12.20% 36.59%\n", "Total 29.27% 31.71% 39.02% 100.00%" ] }, "execution_count": 127, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.pivot_table(hand_df,\n", " index=\"Vendeur\",\n", " columns = \"Produit\",\n", " values=\"Code\",\n", " aggfunc=freq(hand_df[\"Prix\"].count()),\n", " margins=True,\n", " margins_name=\"Total\"\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Ventes sur le mois de Février" ] }, { "cell_type": "code", "execution_count": 19, "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", "
Numero de compteVendeurCodePrixdateProduit
134383080Trantow-BarrowsB1-2000033.692018-02-01 09:04:59Logiciel
135412290Jerde-HilpertS1-2772221.122018-02-01 11:51:46Impression
136412290Jerde-HilpertB1-8648135.992018-02-01 17:24:32Logiciel
137412290Jerde-HilpertB1-2000078.902018-02-01 19:56:48Logiciel
138672390Trantow-BarrowsS1-0653255.822018-02-02 03:45:20Impression
\n", "
" ], "text/plain": [ " Numero de compte Vendeur Code Prix date \\\n", "134 383080 Trantow-Barrows B1-20000 33.69 2018-02-01 09:04:59 \n", "135 412290 Jerde-Hilpert S1-27722 21.12 2018-02-01 11:51:46 \n", "136 412290 Jerde-Hilpert B1-86481 35.99 2018-02-01 17:24:32 \n", "137 412290 Jerde-Hilpert B1-20000 78.90 2018-02-01 19:56:48 \n", "138 672390 Trantow-Barrows S1-06532 55.82 2018-02-02 03:45:20 \n", "\n", " Produit \n", "134 Logiciel \n", "135 Impression \n", "136 Logiciel \n", "137 Logiciel \n", "138 Impression " ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "feb_df = df.loc[(df.date < \"2018-03-01\") & (df.date >= \"2018-02-01\")]\n", "feb_df.head()" ] }, { "cell_type": "code", "execution_count": 60, "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", "
ProduitImpressionLogicielOrdinateurTotal
Vendeur
Barton LLC512219
Jerde-Hilpert65617
Kassulke, Ondricka and Metz69520
Kulas Inc615324
Trantow-Barrows138728
Total364923108
\n", "
" ], "text/plain": [ "Produit Impression Logiciel Ordinateur Total\n", "Vendeur \n", "Barton LLC 5 12 2 19\n", "Jerde-Hilpert 6 5 6 17\n", "Kassulke, Ondricka and Metz 6 9 5 20\n", "Kulas Inc 6 15 3 24\n", "Trantow-Barrows 13 8 7 28\n", "Total 36 49 23 108" ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.pivot_table(feb_df,\n", " index=\"Vendeur\",\n", " columns = \"Produit\",\n", " values=\"Code\",\n", " aggfunc=\"count\",\n", " margins=True,\n", " margins_name=\"Total\"\n", " )" ] }, { "cell_type": "code", "execution_count": 61, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\\begin{tabular}{lrrrr}\n", "\\toprule\n", "\\textbf{Produit} & Impression & Logiciel & Ordinateur & Total \\\\\n", "\\textbf{Vendeur } & & & & \\\\\n", "\\midrule\n", "\\textbf{Barton LLC } & 5 & 12 & 2 & 19 \\\\\n", "\\textbf{Jerde-Hilpert } & 6 & 5 & 6 & 17 \\\\\n", "\\textbf{Kassulke, Ondricka and Metz} & 6 & 9 & 5 & 20 \\\\\n", "\\textbf{Kulas Inc } & 6 & 15 & 3 & 24 \\\\\n", "\\textbf{Trantow-Barrows } & 13 & 8 & 7 & 28 \\\\\n", "\\textbf{Total } & 36 & 49 & 23 & 108 \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "source": [ "print(pd.pivot_table(feb_df,\n", " index=\"Vendeur\",\n", " columns = \"Produit\",\n", " values=\"Code\",\n", " aggfunc=\"count\",\n", " margins=True,\n", " margins_name=\"Total\"\n", " )\\\n", " .to_latex(\n", " float_format=\"{:0.0f}\".format,\n", " bold_rows=True\n", ")\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tableau des fréquences marginales" ] }, { "cell_type": "code", "execution_count": 128, "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", "
ProduitImpressionLogicielOrdinateurTotal
Vendeur
Barton LLC4.63%11.11%1.85%17.59%
Jerde-Hilpert5.56%4.63%5.56%15.74%
Kassulke, Ondricka and Metz5.56%8.33%4.63%18.52%
Kulas Inc5.56%13.89%2.78%22.22%
Trantow-Barrows12.04%7.41%6.48%25.93%
Total33.33%45.37%21.30%100.00%
\n", "
" ], "text/plain": [ "Produit Impression Logiciel Ordinateur Total\n", "Vendeur \n", "Barton LLC 4.63% 11.11% 1.85% 17.59%\n", "Jerde-Hilpert 5.56% 4.63% 5.56% 15.74%\n", "Kassulke, Ondricka and Metz 5.56% 8.33% 4.63% 18.52%\n", "Kulas Inc 5.56% 13.89% 2.78% 22.22%\n", "Trantow-Barrows 12.04% 7.41% 6.48% 25.93%\n", "Total 33.33% 45.37% 21.30% 100.00%" ] }, "execution_count": 128, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.pivot_table(feb_df,\n", " index=\"Vendeur\",\n", " columns = \"Produit\",\n", " values=\"Code\",\n", " aggfunc=freq(feb_df[\"Prix\"].count()),\n", " margins=True,\n", " margins_name=\"Total\"\n", " )" ] }, { "cell_type": "code", "execution_count": 132, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\\begin{tabular}{lllll}\n", "\\toprule\n", "\\textbf{Produit} & Impression & Logiciel & Ordinateur & Total \\\\\n", "\\textbf{Vendeur } & & & & \\\\\n", "\\midrule\n", "\\textbf{Barton LLC } & 4.63\\% & 11.11\\% & 1.85\\% & 17.59\\% \\\\\n", "\\textbf{Jerde-Hilpert } & 5.56\\% & 4.63\\% & 5.56\\% & 15.74\\% \\\\\n", "\\textbf{Kassulke, Ondricka and Metz} & 5.56\\% & 8.33\\% & 4.63\\% & 18.52\\% \\\\\n", "\\textbf{Kulas Inc } & 5.56\\% & 13.89\\% & 2.78\\% & 22.22\\% \\\\\n", "\\textbf{Trantow-Barrows } & 12.04\\% & 7.41\\% & 6.48\\% & 25.93\\% \\\\\n", "\\textbf{Total } & 33.33\\% & 45.37\\% & 21.30\\% & 100.00\\% \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "source": [ "print(pd.pivot_table(feb_df,\n", " index=\"Vendeur\",\n", " columns = \"Produit\",\n", " values=\"Code\",\n", " aggfunc=freq(feb_df[\"Prix\"].count()),\n", " margins=True,\n", " margins_name=\"Total\"\n", " )\\\n", " .to_latex(\n", " float_format=\"{:0.0f}\".format,\n", " bold_rows=True\n", ")\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tableau des fréquences conditionnelles au vendeur" ] }, { "cell_type": "code", "execution_count": 143, "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", "
Produit Impression Logiciel Ordinateur Total
Vendeur
Barton LLC26.32%63.16%10.53%100.00%
Jerde-Hilpert35.29%29.41%35.29%100.00%
Kassulke, Ondricka and Metz30.00%45.00%25.00%100.00%
Kulas Inc25.00%62.50%12.50%100.00%
Trantow-Barrows46.43%28.57%25.00%100.00%
" ], "text/plain": [ "" ] }, "execution_count": 143, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vp_df = feb_df.groupby([\"Vendeur\", \"Produit\"])[\"Code\"]\\\n", " .agg(len)\\\n", " .unstack()\\\n", " .assign(\n", " Total=lambda x: x.T.sum()\n", " )\\\n", " .apply(\n", " lambda x: x / x.T.Total,\n", " axis=1\n", " )\n", "vp_df.style.format(\"{:.2%}\")" ] }, { "cell_type": "code", "execution_count": 144, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\\begin{tabular}{lrrrr}\n", "\\toprule\n", "\\textbf{Produit} & Impression & Logiciel & Ordinateur & Total \\\\\n", "\\textbf{Vendeur } & & & & \\\\\n", "\\midrule\n", "\\textbf{Barton LLC } & 26.32\\% & 63.16\\% & 10.53\\% & 100.00\\% \\\\\n", "\\textbf{Jerde-Hilpert } & 35.29\\% & 29.41\\% & 35.29\\% & 100.00\\% \\\\\n", "\\textbf{Kassulke, Ondricka and Metz} & 30.00\\% & 45.00\\% & 25.00\\% & 100.00\\% \\\\\n", "\\textbf{Kulas Inc } & 25.00\\% & 62.50\\% & 12.50\\% & 100.00\\% \\\\\n", "\\textbf{Trantow-Barrows } & 46.43\\% & 28.57\\% & 25.00\\% & 100.00\\% \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "source": [ "print(vp_df.to_latex(\n", " float_format=\"{:.2%}\".format,\n", " bold_rows=True\n", "))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tableau des fréquences conditionnelles au produit" ] }, { "cell_type": "code", "execution_count": 145, "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", "
Produit Impression Logiciel Ordinateur
Vendeur
Barton LLC13.89%24.49%8.70%
Jerde-Hilpert16.67%10.20%26.09%
Kassulke, Ondricka and Metz16.67%18.37%21.74%
Kulas Inc16.67%30.61%13.04%
Trantow-Barrows36.11%16.33%30.43%
Total100.00%100.00%100.00%
" ], "text/plain": [ "" ] }, "execution_count": 145, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vp_df = feb_df.groupby([\"Produit\", \"Vendeur\"])[\"Code\"]\\\n", " .agg(len)\\\n", " .unstack()\\\n", " .assign(\n", " Total=lambda x: x.T.sum()\n", " )\\\n", " .apply(\n", " lambda x: x / x.T.Total,\n", " axis=1\n", " )\n", "vp_df.T.style.format(\"{:.2%}\")" ] }, { "cell_type": "code", "execution_count": 146, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\\begin{tabular}{lrrr}\n", "\\toprule\n", "\\textbf{Produit} & Impression & Logiciel & Ordinateur \\\\\n", "\\textbf{Vendeur } & & & \\\\\n", "\\midrule\n", "\\textbf{Barton LLC } & 13.89\\% & 24.49\\% & 8.70\\% \\\\\n", "\\textbf{Jerde-Hilpert } & 16.67\\% & 10.20\\% & 26.09\\% \\\\\n", "\\textbf{Kassulke, Ondricka and Metz} & 16.67\\% & 18.37\\% & 21.74\\% \\\\\n", "\\textbf{Kulas Inc } & 16.67\\% & 30.61\\% & 13.04\\% \\\\\n", "\\textbf{Trantow-Barrows } & 36.11\\% & 16.33\\% & 30.43\\% \\\\\n", "\\textbf{Total } & 100.00\\% & 100.00\\% & 100.00\\% \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "source": [ "print(vp_df.T.to_latex(\n", " float_format=\"{:.2%}\".format,\n", " bold_rows=True\n", "))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Ventes sur le mois de Mars" ] }, { "cell_type": "code", "execution_count": 22, "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", "
Numero de compteVendeurCodePrixdateProduit
242163416Jerde-HilpertS1-3024865.032018-03-01 16:07:40Impression
243527099Jerde-HilpertS2-8242376.212018-03-01 17:18:01Ordinateur
244527099Jerde-HilpertB1-5080970.782018-03-01 18:53:09Logiciel
245737550Trantow-BarrowsB1-5080950.112018-03-01 23:47:17Logiciel
246688981Kassulke, Ondricka and MetzB1-8648197.162018-03-02 01:46:44Logiciel
\n", "
" ], "text/plain": [ " Numero de compte Vendeur Code Prix \\\n", "242 163416 Jerde-Hilpert S1-30248 65.03 \n", "243 527099 Jerde-Hilpert S2-82423 76.21 \n", "244 527099 Jerde-Hilpert B1-50809 70.78 \n", "245 737550 Trantow-Barrows B1-50809 50.11 \n", "246 688981 Kassulke, Ondricka and Metz B1-86481 97.16 \n", "\n", " date Produit \n", "242 2018-03-01 16:07:40 Impression \n", "243 2018-03-01 17:18:01 Ordinateur \n", "244 2018-03-01 18:53:09 Logiciel \n", "245 2018-03-01 23:47:17 Logiciel \n", "246 2018-03-02 01:46:44 Logiciel " ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "march_df = df.loc[(df.date < \"2018-04-01\") & (df.date >= \"2018-03-01\")]\n", "march_df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Croisement de ventes entre vendeurs et produits" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 23, "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", "
ProduitImpressionLogicielOrdinateurTotal
Vendeur
Barton LLC77822
Jerde-Hilpert913931
Kassulke, Ondricka and Metz6121230
Kulas Inc1351331
Trantow-Barrows1111628
Total464848142
\n", "
" ], "text/plain": [ "Produit Impression Logiciel Ordinateur Total\n", "Vendeur \n", "Barton LLC 7 7 8 22\n", "Jerde-Hilpert 9 13 9 31\n", "Kassulke, Ondricka and Metz 6 12 12 30\n", "Kulas Inc 13 5 13 31\n", "Trantow-Barrows 11 11 6 28\n", "Total 46 48 48 142" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.pivot_table(march_df,\n", " index=\"Vendeur\",\n", " columns = \"Produit\",\n", " values=\"Code\",\n", " aggfunc=\"count\",\n", " margins=True,\n", " margins_name=\"Total\"\n", " )" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\\begin{tabular}{lrrrr}\n", "\\toprule\n", "\\textbf{Produit} & Impression & Logiciel & Ordinateur & Total \\\\\n", "\\textbf{Vendeur } & & & & \\\\\n", "\\midrule\n", "\\textbf{Barton LLC } & 7 & 7 & 8 & 22 \\\\\n", "\\textbf{Jerde-Hilpert } & 9 & 13 & 9 & 31 \\\\\n", "\\textbf{Kassulke, Ondricka and Metz} & 6 & 12 & 12 & 30 \\\\\n", "\\textbf{Kulas Inc } & 13 & 5 & 13 & 31 \\\\\n", "\\textbf{Trantow-Barrows } & 11 & 11 & 6 & 28 \\\\\n", "\\textbf{Total } & 46 & 48 & 48 & 142 \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "source": [ "print(pd.pivot_table(march_df,\n", " index=\"Vendeur\",\n", " columns = \"Produit\",\n", " values=\"Code\",\n", " aggfunc=\"count\",\n", " margins=True,\n", " margins_name=\"Total\"\n", " )\\\n", " .to_latex(\n", " float_format=\"{:0.0f}\".format,\n", " bold_rows=True\n", ")\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fréquences marginales" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "scrolled": true }, "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", "
ProduitImpressionLogicielOrdinateurTotal
Vendeur
Barton LLC17.07%17.07%19.51%53.66%
Jerde-Hilpert21.95%31.71%21.95%75.61%
Kassulke, Ondricka and Metz14.63%29.27%29.27%73.17%
Kulas Inc31.71%12.20%31.71%75.61%
Trantow-Barrows26.83%26.83%14.63%68.29%
Total112.20%117.07%117.07%346.34%
\n", "
" ], "text/plain": [ "Produit Impression Logiciel Ordinateur Total\n", "Vendeur \n", "Barton LLC 17.07% 17.07% 19.51% 53.66%\n", "Jerde-Hilpert 21.95% 31.71% 21.95% 75.61%\n", "Kassulke, Ondricka and Metz 14.63% 29.27% 29.27% 73.17%\n", "Kulas Inc 31.71% 12.20% 31.71% 75.61%\n", "Trantow-Barrows 26.83% 26.83% 14.63% 68.29%\n", "Total 112.20% 117.07% 117.07% 346.34%" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.pivot_table(march_df,\n", " index=\"Vendeur\",\n", " columns = \"Produit\",\n", " values=\"Code\",\n", " aggfunc=freq,\n", " margins=True,\n", " margins_name=\"Total\"\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Et les 2 en même temps?" ] }, { "cell_type": "code", "execution_count": 26, "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", "
Numero de compteVendeurCodePrixdateProduitMois
134383080Trantow-BarrowsB1-2000033.692018-02-01 09:04:59Logicielfévrier
135412290Jerde-HilpertS1-2772221.122018-02-01 11:51:46Impressionfévrier
136412290Jerde-HilpertB1-8648135.992018-02-01 17:24:32Logicielfévrier
137412290Jerde-HilpertB1-2000078.902018-02-01 19:56:48Logicielfévrier
138672390Trantow-BarrowsS1-0653255.822018-02-02 03:45:20Impressionfévrier
\n", "
" ], "text/plain": [ " Numero de compte Vendeur Code Prix date \\\n", "134 383080 Trantow-Barrows B1-20000 33.69 2018-02-01 09:04:59 \n", "135 412290 Jerde-Hilpert S1-27722 21.12 2018-02-01 11:51:46 \n", "136 412290 Jerde-Hilpert B1-86481 35.99 2018-02-01 17:24:32 \n", "137 412290 Jerde-Hilpert B1-20000 78.90 2018-02-01 19:56:48 \n", "138 672390 Trantow-Barrows S1-06532 55.82 2018-02-02 03:45:20 \n", "\n", " Produit Mois \n", "134 Logiciel février \n", "135 Impression février \n", "136 Logiciel février \n", "137 Logiciel février \n", "138 Impression février " ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "both_df = df.loc[(df.date < \"2018-04-01\") & (df.date >= \"2018-02-01\")].assign(\n", " Mois=lambda x: x.date.dt.strftime(\"%B\")\n", ")\n", "both_df.head()" ] }, { "cell_type": "code", "execution_count": 29, "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", " \n", " \n", " \n", " \n", " \n", "
Moisfévriermars
ProduitImpressionLogicielOrdinateurImpressionLogicielOrdinateur
Vendeur
Barton LLC5122778
Jerde-Hilpert6569139
Kassulke, Ondricka and Metz69561212
Kulas Inc615313513
Trantow-Barrows138711116
\n", "
" ], "text/plain": [ "Mois février mars \\\n", "Produit Impression Logiciel Ordinateur Impression \n", "Vendeur \n", "Barton LLC 5 12 2 7 \n", "Jerde-Hilpert 6 5 6 9 \n", "Kassulke, Ondricka and Metz 6 9 5 6 \n", "Kulas Inc 6 15 3 13 \n", "Trantow-Barrows 13 8 7 11 \n", "\n", "Mois \n", "Produit Logiciel Ordinateur \n", "Vendeur \n", "Barton LLC 7 8 \n", "Jerde-Hilpert 13 9 \n", "Kassulke, Ondricka and Metz 12 12 \n", "Kulas Inc 5 13 \n", "Trantow-Barrows 11 6 " ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.pivot_table(both_df,\n", " index=\"Vendeur\",\n", " columns = [\"Mois\",\"Produit\"],\n", " values=\"Code\",\n", " aggfunc=\"count\",\n", " #margins=True,\n", " #margins_name=\"Total\"\n", " )" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\\begin{tabular}{lrrrrrr}\n", "\\toprule\n", "\\textbf{Mois} & \\multicolumn{3}{l}{février} & \\multicolumn{3}{l}{mars} \\\\\n", "\\textbf{Produit} & Impression & Logiciel & Ordinateur & Impression & Logiciel & Ordinateur \\\\\n", "\\textbf{Vendeur } & & & & & & \\\\\n", "\\midrule\n", "\\textbf{Barton LLC } & 5 & 12 & 2 & 7 & 7 & 8 \\\\\n", "\\textbf{Jerde-Hilpert } & 6 & 5 & 6 & 9 & 13 & 9 \\\\\n", "\\textbf{Kassulke, Ondricka and Metz} & 6 & 9 & 5 & 6 & 12 & 12 \\\\\n", "\\textbf{Kulas Inc } & 6 & 15 & 3 & 13 & 5 & 13 \\\\\n", "\\textbf{Trantow-Barrows } & 13 & 8 & 7 & 11 & 11 & 6 \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "source": [ "print(pd.pivot_table(both_df,\n", " index=\"Vendeur\",\n", " columns = [\"Mois\",\"Produit\"],\n", " values=\"Code\",\n", " aggfunc=\"count\",\n", " #margins=True,\n", " #margins_name=\"Total\"\n", " )\\\n", ".to_latex(\n", " float_format=\"{:0.0f}\".format,\n", " bold_rows=True\n", ")\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.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }