{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "be628bfc-0bca-48b0-97c9-29063289127e",
   "metadata": {},
   "source": [
    "# Statistiques descriptives : compagnies offrant des spectacles"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0bf5450b-f44d-430a-aed7-d875dc365048",
   "metadata": {},
   "source": [
    "## Importations et chargement des données"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "aa915888-cede-4eb0-8a26-7df573d29a3e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import os\n",
    "import s3fs\n",
    "import warnings\n",
    "from datetime import date, timedelta, datetime\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "17949e81-c30b-4fdf-9872-d7dc2b22ba9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import KPI construction functions\n",
    "#exec(open('0_KPI_functions.py').read())\n",
    "exec(open('../0_KPI_functions.py').read())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9c1737a2-bad8-4266-8dec-452085d8cfe7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['projet-bdc2324-team1/0_Input/Company_10/campaigns_information.csv',\n",
       " 'projet-bdc2324-team1/0_Input/Company_10/customerplus_cleaned.csv',\n",
       " 'projet-bdc2324-team1/0_Input/Company_10/products_purchased_reduced.csv',\n",
       " 'projet-bdc2324-team1/0_Input/Company_10/target_information.csv']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create filesystem object\n",
    "S3_ENDPOINT_URL = \"https://\" + os.environ[\"AWS_S3_ENDPOINT\"]\n",
    "fs = s3fs.S3FileSystem(client_kwargs={'endpoint_url': S3_ENDPOINT_URL})\n",
    "\n",
    "BUCKET = \"projet-bdc2324-team1/0_Input/Company_10\"\n",
    "fs.ls(BUCKET)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a35dc2f6-2017-4b21-abd2-2c4c112c96b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "dic_base=['campaigns_information','customerplus_cleaned','products_purchased_reduced','target_information']\n",
    "for nom_base in dic_base:\n",
    "    FILE_PATH_S3_fanta = 'projet-bdc2324-team1/0_Input/Company_10/' + nom_base + '.csv'\n",
    "    with fs.open(FILE_PATH_S3_fanta, mode=\"rb\") as file_in:\n",
    "        globals()[nom_base] = pd.read_csv(file_in, sep=\",\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "40b705eb-fd18-436b-b150-61611a3c6a84",
   "metadata": {},
   "outputs": [],
   "source": [
    "# fonction permettant d'extraire une table à partir du numéro de la compagnie (directory_path)\n",
    "\n",
    "def display_databases(directory_path, file_name, datetime_col = None):\n",
    "    \"\"\"\n",
    "    This function returns the file from s3 storage \n",
    "    \"\"\"\n",
    "    file_path = \"projet-bdc2324-team1\" + \"/0_Input/Company_\" + directory_path + \"/\" + file_name + \".csv\"\n",
    "    print(\"File path : \", file_path)\n",
    "    with fs.open(file_path, mode=\"rb\") as file_in:\n",
    "        df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)        \n",
    "    return df \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c56decc3-de19-4786-82a4-1386c72a6bfb",
   "metadata": {},
   "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>id</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>target_name</th>\n",
       "      <th>target_type_is_import</th>\n",
       "      <th>target_type_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1165098</td>\n",
       "      <td>618562</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1165100</td>\n",
       "      <td>618559</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1165101</td>\n",
       "      <td>618561</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1165102</td>\n",
       "      <td>618560</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1165103</td>\n",
       "      <td>618558</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69253</th>\n",
       "      <td>1698158</td>\n",
       "      <td>18580</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69254</th>\n",
       "      <td>1698159</td>\n",
       "      <td>18569</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69255</th>\n",
       "      <td>1698160</td>\n",
       "      <td>2962</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69256</th>\n",
       "      <td>1698161</td>\n",
       "      <td>3825</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69257</th>\n",
       "      <td>1698162</td>\n",
       "      <td>5731</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>69258 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            id  customer_id           target_name  target_type_is_import  \\\n",
       "0      1165098       618562  Newsletter mensuelle                  False   \n",
       "1      1165100       618559  Newsletter mensuelle                  False   \n",
       "2      1165101       618561  Newsletter mensuelle                  False   \n",
       "3      1165102       618560  Newsletter mensuelle                  False   \n",
       "4      1165103       618558  Newsletter mensuelle                  False   \n",
       "...        ...          ...                   ...                    ...   \n",
       "69253  1698158        18580  Newsletter mensuelle                  False   \n",
       "69254  1698159        18569  Newsletter mensuelle                  False   \n",
       "69255  1698160         2962  Newsletter mensuelle                  False   \n",
       "69256  1698161         3825  Newsletter mensuelle                  False   \n",
       "69257  1698162         5731  Newsletter mensuelle                  False   \n",
       "\n",
       "           target_type_name  \n",
       "0      manual_static_filter  \n",
       "1      manual_static_filter  \n",
       "2      manual_static_filter  \n",
       "3      manual_static_filter  \n",
       "4      manual_static_filter  \n",
       "...                     ...  \n",
       "69253  manual_static_filter  \n",
       "69254  manual_static_filter  \n",
       "69255  manual_static_filter  \n",
       "69256  manual_static_filter  \n",
       "69257  manual_static_filter  \n",
       "\n",
       "[69258 rows x 5 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "target_information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c825d64b-356c-4b71-aa3c-90e0dd7ca092",
   "metadata": {},
   "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>ticket_id</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>purchase_id</th>\n",
       "      <th>event_type_id</th>\n",
       "      <th>supplier_name</th>\n",
       "      <th>purchase_date</th>\n",
       "      <th>amount</th>\n",
       "      <th>is_full_price</th>\n",
       "      <th>name_event_types</th>\n",
       "      <th>name_facilities</th>\n",
       "      <th>name_categories</th>\n",
       "      <th>name_events</th>\n",
       "      <th>name_seasons</th>\n",
       "      <th>start_date_time</th>\n",
       "      <th>end_date_time</th>\n",
       "      <th>open</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1799177</td>\n",
       "      <td>36984</td>\n",
       "      <td>409613</td>\n",
       "      <td>2</td>\n",
       "      <td>guichet</td>\n",
       "      <td>2016-04-28 17:58:26+02:00</td>\n",
       "      <td>9.0</td>\n",
       "      <td>False</td>\n",
       "      <td>danse</td>\n",
       "      <td>le grand t</td>\n",
       "      <td>abo t gourmand jeune</td>\n",
       "      <td>aringa rossa</td>\n",
       "      <td>test 2016/2017</td>\n",
       "      <td>2016-09-27 00:00:00+02:00</td>\n",
       "      <td>1901-01-01 00:09:21+00:09</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1799178</td>\n",
       "      <td>36984</td>\n",
       "      <td>409613</td>\n",
       "      <td>3</td>\n",
       "      <td>guichet</td>\n",
       "      <td>2016-04-28 17:58:26+02:00</td>\n",
       "      <td>9.0</td>\n",
       "      <td>False</td>\n",
       "      <td>cirque</td>\n",
       "      <td>le grand t</td>\n",
       "      <td>abo t gourmand jeune</td>\n",
       "      <td>5èmes hurlants</td>\n",
       "      <td>test 2016/2017</td>\n",
       "      <td>2016-11-18 00:00:00+01:00</td>\n",
       "      <td>1901-01-01 00:09:21+00:09</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1799179</td>\n",
       "      <td>36984</td>\n",
       "      <td>409613</td>\n",
       "      <td>1</td>\n",
       "      <td>guichet</td>\n",
       "      <td>2016-04-28 17:58:26+02:00</td>\n",
       "      <td>9.0</td>\n",
       "      <td>False</td>\n",
       "      <td>théâtre</td>\n",
       "      <td>le grand t</td>\n",
       "      <td>abo t gourmand jeune</td>\n",
       "      <td>dom juan</td>\n",
       "      <td>test 2016/2017</td>\n",
       "      <td>2016-12-07 00:00:00+01:00</td>\n",
       "      <td>1901-01-01 00:09:21+00:09</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1799180</td>\n",
       "      <td>36984</td>\n",
       "      <td>409613</td>\n",
       "      <td>1</td>\n",
       "      <td>guichet</td>\n",
       "      <td>2016-04-28 17:58:26+02:00</td>\n",
       "      <td>9.0</td>\n",
       "      <td>False</td>\n",
       "      <td>théâtre</td>\n",
       "      <td>le grand t</td>\n",
       "      <td>abo t gourmand jeune</td>\n",
       "      <td>vanishing point</td>\n",
       "      <td>test 2016/2017</td>\n",
       "      <td>2017-01-04 00:00:00+01:00</td>\n",
       "      <td>1901-01-01 00:09:21+00:09</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1799181</td>\n",
       "      <td>36984</td>\n",
       "      <td>409613</td>\n",
       "      <td>3</td>\n",
       "      <td>guichet</td>\n",
       "      <td>2016-04-28 17:58:26+02:00</td>\n",
       "      <td>12.0</td>\n",
       "      <td>False</td>\n",
       "      <td>cirque</td>\n",
       "      <td>la cite des congres</td>\n",
       "      <td>abo t gourmand jeune</td>\n",
       "      <td>a o lang pho</td>\n",
       "      <td>test 2016/2017</td>\n",
       "      <td>2017-01-03 00:00:00+01:00</td>\n",
       "      <td>1901-01-01 00:09:21+00:09</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>492309</th>\n",
       "      <td>3252232</td>\n",
       "      <td>621716</td>\n",
       "      <td>710062</td>\n",
       "      <td>1</td>\n",
       "      <td>guichet</td>\n",
       "      <td>2023-03-09 12:08:45+01:00</td>\n",
       "      <td>7.0</td>\n",
       "      <td>False</td>\n",
       "      <td>théâtre</td>\n",
       "      <td>cap nort</td>\n",
       "      <td>tarif sco co 1 seance scolaire</td>\n",
       "      <td>sur moi, le temps</td>\n",
       "      <td>2022/2023</td>\n",
       "      <td>2023-03-13 14:00:00+01:00</td>\n",
       "      <td>1901-01-01 00:09:21+00:09</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>492310</th>\n",
       "      <td>3252233</td>\n",
       "      <td>621716</td>\n",
       "      <td>710062</td>\n",
       "      <td>1</td>\n",
       "      <td>guichet</td>\n",
       "      <td>2023-03-09 12:08:45+01:00</td>\n",
       "      <td>7.0</td>\n",
       "      <td>False</td>\n",
       "      <td>théâtre</td>\n",
       "      <td>cap nort</td>\n",
       "      <td>tarif sco co 1 seance scolaire</td>\n",
       "      <td>sur moi, le temps</td>\n",
       "      <td>2022/2023</td>\n",
       "      <td>2023-03-13 14:00:00+01:00</td>\n",
       "      <td>1901-01-01 00:09:21+00:09</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>492311</th>\n",
       "      <td>3252234</td>\n",
       "      <td>621716</td>\n",
       "      <td>710062</td>\n",
       "      <td>1</td>\n",
       "      <td>guichet</td>\n",
       "      <td>2023-03-09 12:08:45+01:00</td>\n",
       "      <td>7.0</td>\n",
       "      <td>False</td>\n",
       "      <td>théâtre</td>\n",
       "      <td>cap nort</td>\n",
       "      <td>tarif sco co 1 seance scolaire</td>\n",
       "      <td>sur moi, le temps</td>\n",
       "      <td>2022/2023</td>\n",
       "      <td>2023-03-13 14:00:00+01:00</td>\n",
       "      <td>1901-01-01 00:09:21+00:09</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>492312</th>\n",
       "      <td>3252235</td>\n",
       "      <td>621716</td>\n",
       "      <td>710062</td>\n",
       "      <td>1</td>\n",
       "      <td>guichet</td>\n",
       "      <td>2023-03-09 12:08:45+01:00</td>\n",
       "      <td>7.0</td>\n",
       "      <td>False</td>\n",
       "      <td>théâtre</td>\n",
       "      <td>cap nort</td>\n",
       "      <td>tarif sco co 1 seance scolaire</td>\n",
       "      <td>sur moi, le temps</td>\n",
       "      <td>2022/2023</td>\n",
       "      <td>2023-03-13 14:00:00+01:00</td>\n",
       "      <td>1901-01-01 00:09:21+00:09</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>492313</th>\n",
       "      <td>3252236</td>\n",
       "      <td>621716</td>\n",
       "      <td>710062</td>\n",
       "      <td>1</td>\n",
       "      <td>guichet</td>\n",
       "      <td>2023-03-09 12:08:45+01:00</td>\n",
       "      <td>7.0</td>\n",
       "      <td>False</td>\n",
       "      <td>théâtre</td>\n",
       "      <td>cap nort</td>\n",
       "      <td>tarif sco co 1 seance scolaire</td>\n",
       "      <td>sur moi, le temps</td>\n",
       "      <td>2022/2023</td>\n",
       "      <td>2023-03-13 14:00:00+01:00</td>\n",
       "      <td>1901-01-01 00:09:21+00:09</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>492314 rows × 16 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        ticket_id  customer_id  purchase_id  event_type_id supplier_name  \\\n",
       "0         1799177        36984       409613              2       guichet   \n",
       "1         1799178        36984       409613              3       guichet   \n",
       "2         1799179        36984       409613              1       guichet   \n",
       "3         1799180        36984       409613              1       guichet   \n",
       "4         1799181        36984       409613              3       guichet   \n",
       "...           ...          ...          ...            ...           ...   \n",
       "492309    3252232       621716       710062              1       guichet   \n",
       "492310    3252233       621716       710062              1       guichet   \n",
       "492311    3252234       621716       710062              1       guichet   \n",
       "492312    3252235       621716       710062              1       guichet   \n",
       "492313    3252236       621716       710062              1       guichet   \n",
       "\n",
       "                    purchase_date  amount  is_full_price name_event_types  \\\n",
       "0       2016-04-28 17:58:26+02:00     9.0          False            danse   \n",
       "1       2016-04-28 17:58:26+02:00     9.0          False           cirque   \n",
       "2       2016-04-28 17:58:26+02:00     9.0          False          théâtre   \n",
       "3       2016-04-28 17:58:26+02:00     9.0          False          théâtre   \n",
       "4       2016-04-28 17:58:26+02:00    12.0          False           cirque   \n",
       "...                           ...     ...            ...              ...   \n",
       "492309  2023-03-09 12:08:45+01:00     7.0          False          théâtre   \n",
       "492310  2023-03-09 12:08:45+01:00     7.0          False          théâtre   \n",
       "492311  2023-03-09 12:08:45+01:00     7.0          False          théâtre   \n",
       "492312  2023-03-09 12:08:45+01:00     7.0          False          théâtre   \n",
       "492313  2023-03-09 12:08:45+01:00     7.0          False          théâtre   \n",
       "\n",
       "            name_facilities                 name_categories  \\\n",
       "0                le grand t            abo t gourmand jeune   \n",
       "1                le grand t            abo t gourmand jeune   \n",
       "2                le grand t            abo t gourmand jeune   \n",
       "3                le grand t            abo t gourmand jeune   \n",
       "4       la cite des congres            abo t gourmand jeune   \n",
       "...                     ...                             ...   \n",
       "492309             cap nort  tarif sco co 1 seance scolaire   \n",
       "492310             cap nort  tarif sco co 1 seance scolaire   \n",
       "492311             cap nort  tarif sco co 1 seance scolaire   \n",
       "492312             cap nort  tarif sco co 1 seance scolaire   \n",
       "492313             cap nort  tarif sco co 1 seance scolaire   \n",
       "\n",
       "              name_events    name_seasons            start_date_time  \\\n",
       "0            aringa rossa  test 2016/2017  2016-09-27 00:00:00+02:00   \n",
       "1          5èmes hurlants  test 2016/2017  2016-11-18 00:00:00+01:00   \n",
       "2                dom juan  test 2016/2017  2016-12-07 00:00:00+01:00   \n",
       "3         vanishing point  test 2016/2017  2017-01-04 00:00:00+01:00   \n",
       "4            a o lang pho  test 2016/2017  2017-01-03 00:00:00+01:00   \n",
       "...                   ...             ...                        ...   \n",
       "492309  sur moi, le temps       2022/2023  2023-03-13 14:00:00+01:00   \n",
       "492310  sur moi, le temps       2022/2023  2023-03-13 14:00:00+01:00   \n",
       "492311  sur moi, le temps       2022/2023  2023-03-13 14:00:00+01:00   \n",
       "492312  sur moi, le temps       2022/2023  2023-03-13 14:00:00+01:00   \n",
       "492313  sur moi, le temps       2022/2023  2023-03-13 14:00:00+01:00   \n",
       "\n",
       "                    end_date_time  open  \n",
       "0       1901-01-01 00:09:21+00:09  True  \n",
       "1       1901-01-01 00:09:21+00:09  True  \n",
       "2       1901-01-01 00:09:21+00:09  True  \n",
       "3       1901-01-01 00:09:21+00:09  True  \n",
       "4       1901-01-01 00:09:21+00:09  True  \n",
       "...                           ...   ...  \n",
       "492309  1901-01-01 00:09:21+00:09  True  \n",
       "492310  1901-01-01 00:09:21+00:09  True  \n",
       "492311  1901-01-01 00:09:21+00:09  True  \n",
       "492312  1901-01-01 00:09:21+00:09  True  \n",
       "492313  1901-01-01 00:09:21+00:09  True  \n",
       "\n",
       "[492314 rows x 16 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "products_purchased_reduced"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "afd044b8-ac83-4a35-b959-700cae0b3b41",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_10/customerplus_cleaned.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_10/campaigns_information.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_10/products_purchased_reduced.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_10/target_information.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n",
      "<string>:27: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_11/customerplus_cleaned.csv\n",
      "File path :  projet-bdc2324-team1/0_Input/Company_11/campaigns_information.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n",
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_11/products_purchased_reduced.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_11/target_information.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n",
      "<string>:27: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_12/customerplus_cleaned.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_12/campaigns_information.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_12/products_purchased_reduced.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n",
      "/tmp/ipykernel_430/3170175140.py:10: DtypeWarning: Columns (4,8,10) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_12/target_information.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n",
      "<string>:27: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_13/customerplus_cleaned.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_13/campaigns_information.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_13/products_purchased_reduced.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_13/target_information.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n",
      "<string>:27: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_14/customerplus_cleaned.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_14/campaigns_information.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_14/products_purchased_reduced.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n",
      "/tmp/ipykernel_430/3170175140.py:10: DtypeWarning: Columns (8,9) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_14/target_information.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3170175140.py:10: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n",
      "<string>:27: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n"
     ]
    }
   ],
   "source": [
    "# création des bases contenant les KPI pour les 5 compagnies de spectacle\n",
    "\n",
    "# liste des compagnies de spectacle\n",
    "nb_compagnie=['10','11','12','13','14']\n",
    "\n",
    "# début de la boucle permettant de générer des datasets agrégés pour les 5 compagnies de spectacle\n",
    "for directory_path in nb_compagnie:\n",
    "    df_customerplus_clean_0 = display_databases(directory_path, file_name = \"customerplus_cleaned\")\n",
    "    df_campaigns_information = display_databases(directory_path, file_name = \"campaigns_information\", datetime_col = ['opened_at', 'sent_at', 'campaign_sent_at'])\n",
    "    df_products_purchased_reduced = display_databases(directory_path, file_name = \"products_purchased_reduced\", datetime_col = ['purchase_date'])\n",
    "    df_target_information = display_databases(directory_path, file_name = \"target_information\")\n",
    "    \n",
    "    df_campaigns_kpi = campaigns_kpi_function(campaigns_information = df_campaigns_information) \n",
    "    df_tickets_kpi = tickets_kpi_function(tickets_information = df_products_purchased_reduced)\n",
    "    df_customerplus_clean = customerplus_kpi_function(customerplus_clean = df_customerplus_clean_0)\n",
    "\n",
    "        \n",
    "# creation de la colonne Number compagnie, qui permettra d'agréger les résultats\n",
    "    df_tickets_kpi[\"number_compagny\"]=int(directory_path)\n",
    "    df_campaigns_kpi[\"number_compagny\"]=int(directory_path)\n",
    "    df_customerplus_clean[\"number_compagny\"]=int(directory_path)\n",
    "    df_target_information[\"number_compagny\"]=int(directory_path)\n",
    "\n",
    "    if nb_compagnie.index(directory_path)>=1:\n",
    "        customerplus_clean_spectacle=pd.concat([customerplus_clean_spectacle,df_customerplus_clean],axis=0)\n",
    "        campaigns_information_spectacle=pd.concat([campaigns_information_spectacle,df_campaigns_kpi],axis=0)\n",
    "        products_purchased_reduced_spectacle=pd.concat([products_purchased_reduced_spectacle,df_tickets_kpi],axis=0)\n",
    "        target_information_spectacle=pd.concat([target_information_spectacle,df_target_information],axis=0)\n",
    "    else:\n",
    "        customerplus_clean_spectacle=df_customerplus_clean\n",
    "        campaigns_information_spectacle=df_campaigns_kpi\n",
    "        products_purchased_reduced_spectacle=df_tickets_kpi\n",
    "        target_information_spectacle=df_target_information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "b5a4a031-9533-4a50-8569-5f4246691a7a",
   "metadata": {},
   "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>customer_id</th>\n",
       "      <th>street_id</th>\n",
       "      <th>structure_id</th>\n",
       "      <th>mcp_contact_id</th>\n",
       "      <th>fidelity</th>\n",
       "      <th>tenant_id</th>\n",
       "      <th>is_partner</th>\n",
       "      <th>deleted_at</th>\n",
       "      <th>gender</th>\n",
       "      <th>is_email_true</th>\n",
       "      <th>...</th>\n",
       "      <th>purchase_count</th>\n",
       "      <th>first_buying_date</th>\n",
       "      <th>country</th>\n",
       "      <th>gender_label</th>\n",
       "      <th>gender_female</th>\n",
       "      <th>gender_male</th>\n",
       "      <th>gender_other</th>\n",
       "      <th>country_fr</th>\n",
       "      <th>has_tags</th>\n",
       "      <th>number_compagny</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2</td>\n",
       "      <td>139</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18031</th>\n",
       "      <td>2</td>\n",
       "      <td>319517</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>1556</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>2020-01-01 14:06:52+00:00</td>\n",
       "      <td>fr</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>291642</th>\n",
       "      <td>2</td>\n",
       "      <td>757541</td>\n",
       "      <td>303.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1</td>\n",
       "      <td>862</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>2016-09-08 14:50:00+00:00</td>\n",
       "      <td>fr</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 29 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        customer_id  street_id  structure_id  mcp_contact_id  fidelity  \\\n",
       "17                2        139           NaN             NaN         0   \n",
       "18031             2     319517           NaN             NaN         0   \n",
       "291642            2     757541         303.0             5.0         1   \n",
       "\n",
       "        tenant_id  is_partner  deleted_at  gender  is_email_true  ...  \\\n",
       "17            875       False         NaN       2          False  ...   \n",
       "18031        1556       False         NaN       0           True  ...   \n",
       "291642        862       False         NaN       1           True  ...   \n",
       "\n",
       "        purchase_count          first_buying_date  country  gender_label  \\\n",
       "17                   3                        NaN      NaN         other   \n",
       "18031                2  2020-01-01 14:06:52+00:00       fr        female   \n",
       "291642               3  2016-09-08 14:50:00+00:00       fr          male   \n",
       "\n",
       "        gender_female  gender_male  gender_other  country_fr  has_tags  \\\n",
       "17                  0            0             1         NaN         0   \n",
       "18031               1            0             0         1.0         0   \n",
       "291642              0            1             0         1.0         1   \n",
       "\n",
       "        number_compagny  \n",
       "17                   10  \n",
       "18031                11  \n",
       "291642               14  \n",
       "\n",
       "[3 rows x 29 columns]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customerplus_clean_spectacle[customerplus_clean_spectacle[\"customer_id\"]==2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b9b6ec1f-36fb-4ee9-a1ed-09ff41878005",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'customerplus_clean_spectacle' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mcustomerplus_clean_spectacle\u001b[49m[customerplus_clean_spectacle[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcustomer_id\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m==\u001b[39m\u001b[38;5;241m1\u001b[39m]\n",
      "\u001b[0;31mNameError\u001b[0m: name 'customerplus_clean_spectacle' is not defined"
     ]
    }
   ],
   "source": [
    "customerplus_clean_spectacle[customerplus_clean_spectacle[\"customer_id\"]==1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "a12c1b7d-6f6f-483e-b215-6336d7a51057",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['customer_id', 'street_id', 'structure_id', 'mcp_contact_id',\n",
       "       'fidelity', 'tenant_id', 'is_partner', 'deleted_at', 'gender',\n",
       "       'is_email_true', 'opt_in', 'last_buying_date', 'max_price',\n",
       "       'ticket_sum', 'average_price', 'average_purchase_delay',\n",
       "       'average_price_basket', 'average_ticket_basket', 'total_price',\n",
       "       'purchase_count', 'first_buying_date', 'country', 'gender_label',\n",
       "       'gender_female', 'gender_male', 'gender_other', 'country_fr',\n",
       "       'has_tags', 'number_compagny'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customerplus_clean_spectacle.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6f263e9c-0adf-4f25-8939-7416f3013c04",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "05b9a396-dcd7-4d3d-8b39-5ca48beba4b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "#customerplus_clean_spectacle.isna().sum()\n",
    "#campaigns_information_spectacle.isna().sum()\n",
    "#products_purchased_reduced_spectacle.isna().sum()\n",
    "#target_information_spectacle.isna().sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fff306c2-1d41-4ef6-867b-ba9a7cf4ee68",
   "metadata": {},
   "source": [
    "## Statistiques descriptives"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0549bdc4-edd7-4511-916e-26e94b5a30f5",
   "metadata": {},
   "source": [
    "### 0. Détection du client anonyme (outlier) - utile pour la section 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "5b460061-f8b5-4a6b-ba59-539446d8487f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def outlier_detection(directory_path = \"1\", coupure = 1):\n",
    "    df_tickets = display_databases(directory_path, file_name = 'products_purchased_reduced' , datetime_col = ['purchase_date'])\n",
    "    df_tickets_kpi = tickets_kpi_function(df_tickets)\n",
    "\n",
    "    if directory_path == \"101\" :\n",
    "        df_tickets_1 = display_databases(directory_path, file_name = 'products_purchased_reduced_1' , datetime_col = ['purchase_date'])\n",
    "        df_tickets_kpi_1 = tickets_kpi_function(df_tickets_1)\n",
    "\n",
    "        df_tickets_kpi = pd.concat([df_tickets_kpi, df_tickets_kpi_1])\n",
    "    # Part du CA par customer\n",
    "    total_amount_share = df_tickets_kpi.groupby('customer_id')['total_amount'].sum().reset_index()\n",
    "    total_amount_share['total_amount_entreprise'] = total_amount_share['total_amount'].sum()\n",
    "    total_amount_share['share_total_amount'] = total_amount_share['total_amount']/total_amount_share['total_amount_entreprise']\n",
    "    \n",
    "    total_amount_share_index = total_amount_share.set_index('customer_id')\n",
    "    df_circulaire = total_amount_share_index['total_amount'].sort_values(axis = 0, ascending = False)\n",
    "    \n",
    "    top = df_circulaire[:coupure]\n",
    "    rest = df_circulaire[coupure:]\n",
    "    \n",
    "    # Calculez la somme du reste\n",
    "    rest_sum = rest.sum()\n",
    "    \n",
    "    # Créez une nouvelle série avec les cinq plus grandes parts et 'Autre'\n",
    "    new_series = pd.concat([top, pd.Series([rest_sum], index=['Autre'])])\n",
    "    \n",
    "    # Créez le graphique circulaire\n",
    "    plt.figure(figsize=(3, 3))\n",
    "    plt.pie(new_series, labels=new_series.index, autopct='%1.1f%%', startangle=140, pctdistance=0.5)\n",
    "    plt.axis('equal')  # Assurez-vous que le graphique est un cercle\n",
    "    plt.title('Répartition des montants totaux')\n",
    "    plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "b6417f09-a6c7-4319-95b3-98c95ec5a3b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File path :  projet-bdc2324-team1/0_Input/Company_10/products_purchased_reduced.csv\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_1173/2987234667.py:8: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
      "  df = pd.read_csv(file_in, sep=\",\", parse_dates = datetime_col, date_parser=custom_date_parser)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 19756 characters]",
      "text/plain": [
       "<Figure size 300x300 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "outlier_detection(directory_path=\"10\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42f8171c-e80d-4faa-b278-21fcbe3b242c",
   "metadata": {},
   "source": [
    "### 1. customerplus_clean"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "47f98721-53dd-4f8f-85ac-88043ee8d967",
   "metadata": {},
   "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>customer_id</th>\n",
       "      <th>street_id</th>\n",
       "      <th>structure_id</th>\n",
       "      <th>mcp_contact_id</th>\n",
       "      <th>fidelity</th>\n",
       "      <th>tenant_id</th>\n",
       "      <th>is_partner</th>\n",
       "      <th>deleted_at</th>\n",
       "      <th>gender</th>\n",
       "      <th>is_email_true</th>\n",
       "      <th>...</th>\n",
       "      <th>purchase_count</th>\n",
       "      <th>first_buying_date</th>\n",
       "      <th>country</th>\n",
       "      <th>gender_label</th>\n",
       "      <th>gender_female</th>\n",
       "      <th>gender_male</th>\n",
       "      <th>gender_other</th>\n",
       "      <th>country_fr</th>\n",
       "      <th>has_tags</th>\n",
       "      <th>number_compagny</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>821538</td>\n",
       "      <td>139</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>809126</td>\n",
       "      <td>1063</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11005</td>\n",
       "      <td>1063</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>14</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>17663</td>\n",
       "      <td>12731</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>38100</td>\n",
       "      <td>12395</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>307036</td>\n",
       "      <td>139</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2946</td>\n",
       "      <td>1063</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>18441</td>\n",
       "      <td>11139</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9231</td>\n",
       "      <td>139</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9870</td>\n",
       "      <td>139</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10 rows × 29 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   customer_id  street_id  structure_id  mcp_contact_id  fidelity  tenant_id  \\\n",
       "0       821538        139           NaN             NaN         0        875   \n",
       "1       809126       1063           NaN             NaN         0        875   \n",
       "2        11005       1063           NaN             NaN         0        875   \n",
       "3        17663      12731           NaN             NaN         0        875   \n",
       "4        38100      12395           NaN             NaN         0        875   \n",
       "5       307036        139           NaN             NaN         0        875   \n",
       "6         2946       1063           NaN             NaN         0        875   \n",
       "7        18441      11139           NaN             NaN         0        875   \n",
       "8         9231        139           NaN             NaN         0        875   \n",
       "9         9870        139           NaN             NaN         0        875   \n",
       "\n",
       "   is_partner  deleted_at  gender  is_email_true  ...  purchase_count  \\\n",
       "0       False         NaN       2           True  ...               0   \n",
       "1       False         NaN       2           True  ...               0   \n",
       "2       False         NaN       2          False  ...              14   \n",
       "3       False         NaN       0          False  ...               1   \n",
       "4       False         NaN       0           True  ...               1   \n",
       "5       False         NaN       2           True  ...               1   \n",
       "6       False         NaN       2          False  ...               8   \n",
       "7       False         NaN       2          False  ...               3   \n",
       "8       False         NaN       0           True  ...               1   \n",
       "9       False         NaN       2           True  ...               1   \n",
       "\n",
       "  first_buying_date  country  gender_label  gender_female  gender_male  \\\n",
       "0               NaN      NaN         other              0            0   \n",
       "1               NaN       fr         other              0            0   \n",
       "2               NaN       fr         other              0            0   \n",
       "3               NaN       fr        female              1            0   \n",
       "4               NaN       fr        female              1            0   \n",
       "5               NaN      NaN         other              0            0   \n",
       "6               NaN       fr         other              0            0   \n",
       "7               NaN       fr         other              0            0   \n",
       "8               NaN      NaN        female              1            0   \n",
       "9               NaN      NaN         other              0            0   \n",
       "\n",
       "   gender_other  country_fr  has_tags  number_compagny  \n",
       "0             1         NaN         0               10  \n",
       "1             1         1.0         0               10  \n",
       "2             1         1.0         0               10  \n",
       "3             0         1.0         0               10  \n",
       "4             0         1.0         0               10  \n",
       "5             1         NaN         0               10  \n",
       "6             1         1.0         0               10  \n",
       "7             1         1.0         0               10  \n",
       "8             0         NaN         0               10  \n",
       "9             1         NaN         0               10  \n",
       "\n",
       "[10 rows x 29 columns]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# visu de la table\n",
    "customerplus_clean_spectacle.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "738e063b-f84e-4a00-b35d-6d1d657e3c09",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nombre de lignes de la table :  1523688\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "customer_id                     0\n",
       "street_id                       0\n",
       "structure_id              1460624\n",
       "mcp_contact_id             729167\n",
       "fidelity                        0\n",
       "tenant_id                       0\n",
       "is_partner                      0\n",
       "deleted_at                1523688\n",
       "gender                          0\n",
       "is_email_true                   0\n",
       "opt_in                          0\n",
       "last_buying_date           762879\n",
       "max_price                  762879\n",
       "ticket_sum                      0\n",
       "average_price              667328\n",
       "average_purchase_delay     762915\n",
       "average_price_basket       762915\n",
       "average_ticket_basket      762915\n",
       "total_price                 95551\n",
       "purchase_count                  0\n",
       "first_buying_date          762879\n",
       "country                    429486\n",
       "gender_label                    0\n",
       "gender_female                   0\n",
       "gender_male                     0\n",
       "gender_other                    0\n",
       "country_fr                 429486\n",
       "has_tags                        0\n",
       "number_compagny                 0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# nombre de NaN\n",
    "print(\"Nombre de lignes de la table : \",customerplus_clean_spectacle.shape[0])\n",
    "customerplus_clean_spectacle.isna().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "id": "296e51c5-30ae-4ade-ba3d-4ba4981a8758",
   "metadata": {},
   "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>number_compagny</th>\n",
       "      <th>customer_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>45264</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11</td>\n",
       "      <td>35313</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12</td>\n",
       "      <td>216105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13</td>\n",
       "      <td>388731</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>14</td>\n",
       "      <td>101642</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   number_compagny  customer_id\n",
       "0               10        45264\n",
       "1               11        35313\n",
       "2               12       216105\n",
       "3               13       388731\n",
       "4               14       101642"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# nombre de clients de la compagnie (pas les clients visés par une campagne mais ceux ayant acheté)\n",
    "# on rq le nbre de clients est très variable : de 35k à 389k\n",
    "company_nb_clients = customerplus_clean_spectacle[customerplus_clean_spectacle[\"purchase_count\"]>0].groupby(\"number_compagny\")[\"customer_id\"].count().reset_index()\n",
    "company_nb_clients"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "id": "5845aedf-78ca-4d3d-ad61-3561d4fc1886",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 27868 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Création du barplot\n",
    "plt.bar(company_nb_clients[\"number_compagny\"], company_nb_clients[\"customer_id\"]/1000)\n",
    "\n",
    "# Ajout de titres et d'étiquettes\n",
    "plt.xlabel('Company')\n",
    "plt.ylabel(\"Nombre de clients (milliers)\")\n",
    "plt.title(\"Nombre de clients de chaque compagnie de spectacle\")\n",
    "\n",
    "# Affichage du barplot\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "id": "fd11c547-7128-4ef6-ad7b-4b7c2a30cd9e",
   "metadata": {},
   "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>number_compagny</th>\n",
       "      <th>max_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>13823.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11</td>\n",
       "      <td>108.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12</td>\n",
       "      <td>5000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13</td>\n",
       "      <td>3180.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>14</td>\n",
       "      <td>456.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   number_compagny  max_price\n",
       "0               10    13823.0\n",
       "1               11      108.0\n",
       "2               12     5000.0\n",
       "3               13     3180.0\n",
       "4               14      456.0"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# prix maximal payé par un client pour chaque compagnie - très variable : de 108 à 13823\n",
    "\n",
    "company_max_price = customerplus_clean_spectacle.groupby(\"number_compagny\")[\"max_price\"].max().reset_index()\n",
    "company_max_price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "id": "b8f8f162-4153-4cfe-bfaa-d981d414510d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 31880 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Création du barplot\n",
    "plt.bar(company_max_price[\"number_compagny\"], company_max_price[\"max_price\"])\n",
    "\n",
    "# Ajout de titres et d'étiquettes\n",
    "plt.xlabel('Company')\n",
    "plt.ylabel(\"Prix maximal d'un billet vendu\")\n",
    "plt.title(\"Prix maximal de vente observé par compagnie de spectacle\")\n",
    "\n",
    "# Affichage du barplot\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "bff23e5d-d7ed-4092-ae3c-5df503e54a6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    762879.000000\n",
       "mean          0.079068\n",
       "std           3.969729\n",
       "min           0.000000\n",
       "25%           0.000000\n",
       "50%           0.000000\n",
       "75%           0.000000\n",
       "max        3334.000000\n",
       "Name: purchase_count, dtype: float64"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customerplus_clean_spectacle[customerplus_clean_spectacle[\"first_buying_date\"].isna()][\"purchase_count\"].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "89466dbd-14d2-4ede-9ca0-b9c32b764e25",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    7.608090e+05\n",
       "mean     3.863940e+00\n",
       "std      1.685825e+03\n",
       "min      1.000000e+00\n",
       "25%      1.000000e+00\n",
       "50%      1.000000e+00\n",
       "75%      2.000000e+00\n",
       "max      1.469325e+06\n",
       "Name: purchase_count, dtype: float64"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customerplus_clean_spectacle[~customerplus_clean_spectacle[\"first_buying_date\"].isna()][\"purchase_count\"].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "5f9feae4-35f4-43b6-adeb-f75773900a2d",
   "metadata": {},
   "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>customer_id</th>\n",
       "      <th>street_id</th>\n",
       "      <th>structure_id</th>\n",
       "      <th>mcp_contact_id</th>\n",
       "      <th>fidelity</th>\n",
       "      <th>tenant_id</th>\n",
       "      <th>is_partner</th>\n",
       "      <th>deleted_at</th>\n",
       "      <th>gender</th>\n",
       "      <th>is_email_true</th>\n",
       "      <th>...</th>\n",
       "      <th>first_buying_date</th>\n",
       "      <th>country</th>\n",
       "      <th>gender_label</th>\n",
       "      <th>gender_female</th>\n",
       "      <th>gender_male</th>\n",
       "      <th>gender_other</th>\n",
       "      <th>country_fr</th>\n",
       "      <th>has_tags</th>\n",
       "      <th>number_compagny</th>\n",
       "      <th>already_purchased</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>821538</td>\n",
       "      <td>139</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>809126</td>\n",
       "      <td>1063</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11005</td>\n",
       "      <td>1063</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>17663</td>\n",
       "      <td>12731</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>38100</td>\n",
       "      <td>12395</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>343121</th>\n",
       "      <td>4667645</td>\n",
       "      <td>122</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1534181.0</td>\n",
       "      <td>0</td>\n",
       "      <td>862</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>343122</th>\n",
       "      <td>4667649</td>\n",
       "      <td>122</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1534177.0</td>\n",
       "      <td>0</td>\n",
       "      <td>862</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>343123</th>\n",
       "      <td>4667660</td>\n",
       "      <td>122</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1534165.0</td>\n",
       "      <td>0</td>\n",
       "      <td>862</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>343124</th>\n",
       "      <td>4667679</td>\n",
       "      <td>122</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1534132.0</td>\n",
       "      <td>0</td>\n",
       "      <td>862</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>343125</th>\n",
       "      <td>4667686</td>\n",
       "      <td>122</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1567949.0</td>\n",
       "      <td>0</td>\n",
       "      <td>862</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1523688 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        customer_id  street_id  structure_id  mcp_contact_id  fidelity  \\\n",
       "0            821538        139           NaN             NaN         0   \n",
       "1            809126       1063           NaN             NaN         0   \n",
       "2             11005       1063           NaN             NaN         0   \n",
       "3             17663      12731           NaN             NaN         0   \n",
       "4             38100      12395           NaN             NaN         0   \n",
       "...             ...        ...           ...             ...       ...   \n",
       "343121      4667645        122           NaN       1534181.0         0   \n",
       "343122      4667649        122           NaN       1534177.0         0   \n",
       "343123      4667660        122           NaN       1534165.0         0   \n",
       "343124      4667679        122           NaN       1534132.0         0   \n",
       "343125      4667686        122           NaN       1567949.0         0   \n",
       "\n",
       "        tenant_id  is_partner  deleted_at  gender  is_email_true  ...  \\\n",
       "0             875       False         NaN       2           True  ...   \n",
       "1             875       False         NaN       2           True  ...   \n",
       "2             875       False         NaN       2          False  ...   \n",
       "3             875       False         NaN       0          False  ...   \n",
       "4             875       False         NaN       0           True  ...   \n",
       "...           ...         ...         ...     ...            ...  ...   \n",
       "343121        862       False         NaN       2           True  ...   \n",
       "343122        862       False         NaN       2           True  ...   \n",
       "343123        862       False         NaN       0           True  ...   \n",
       "343124        862       False         NaN       2           True  ...   \n",
       "343125        862       False         NaN       0           True  ...   \n",
       "\n",
       "        first_buying_date country  gender_label  gender_female  gender_male  \\\n",
       "0                     NaN     NaN         other              0            0   \n",
       "1                     NaN      fr         other              0            0   \n",
       "2                     NaN      fr         other              0            0   \n",
       "3                     NaN      fr        female              1            0   \n",
       "4                     NaN      fr        female              1            0   \n",
       "...                   ...     ...           ...            ...          ...   \n",
       "343121                NaN     NaN         other              0            0   \n",
       "343122                NaN     NaN         other              0            0   \n",
       "343123                NaN     NaN        female              1            0   \n",
       "343124                NaN     NaN         other              0            0   \n",
       "343125                NaN     NaN        female              1            0   \n",
       "\n",
       "        gender_other  country_fr  has_tags  number_compagny  already_purchased  \n",
       "0                  1         NaN         0               10              False  \n",
       "1                  1         1.0         0               10              False  \n",
       "2                  1         1.0         0               10              False  \n",
       "3                  0         1.0         0               10              False  \n",
       "4                  0         1.0         0               10              False  \n",
       "...              ...         ...       ...              ...                ...  \n",
       "343121             1         NaN         0               14              False  \n",
       "343122             1         NaN         0               14              False  \n",
       "343123             0         NaN         0               14              False  \n",
       "343124             1         NaN         0               14              False  \n",
       "343125             0         NaN         0               14              False  \n",
       "\n",
       "[1523688 rows x 30 columns]"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customerplus_clean_spectacle[\"already_purchased\"] = customerplus_clean_spectacle[\"first_buying_date\"].isna()==False\n",
    "customerplus_clean_spectacle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "cec4f1eb-cec8-409d-8b2c-1e01f1bf81ff",
   "metadata": {},
   "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>customer_id</th>\n",
       "      <th>street_id</th>\n",
       "      <th>structure_id</th>\n",
       "      <th>mcp_contact_id</th>\n",
       "      <th>fidelity</th>\n",
       "      <th>tenant_id</th>\n",
       "      <th>is_partner</th>\n",
       "      <th>deleted_at</th>\n",
       "      <th>gender</th>\n",
       "      <th>is_email_true</th>\n",
       "      <th>...</th>\n",
       "      <th>first_buying_date</th>\n",
       "      <th>country</th>\n",
       "      <th>gender_label</th>\n",
       "      <th>gender_female</th>\n",
       "      <th>gender_male</th>\n",
       "      <th>gender_other</th>\n",
       "      <th>country_fr</th>\n",
       "      <th>has_tags</th>\n",
       "      <th>number_compagny</th>\n",
       "      <th>already_purchased</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11005</td>\n",
       "      <td>1063</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>17663</td>\n",
       "      <td>12731</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>38100</td>\n",
       "      <td>12395</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>307036</td>\n",
       "      <td>139</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2946</td>\n",
       "      <td>1063</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>875</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>other</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>338933</th>\n",
       "      <td>3625705</td>\n",
       "      <td>648752</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1253864.0</td>\n",
       "      <td>0</td>\n",
       "      <td>862</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>338954</th>\n",
       "      <td>3627626</td>\n",
       "      <td>636890</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1253887.0</td>\n",
       "      <td>0</td>\n",
       "      <td>862</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>338959</th>\n",
       "      <td>3628124</td>\n",
       "      <td>653042</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1253899.0</td>\n",
       "      <td>0</td>\n",
       "      <td>862</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>338986</th>\n",
       "      <td>3631189</td>\n",
       "      <td>648423</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1253928.0</td>\n",
       "      <td>0</td>\n",
       "      <td>862</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>339039</th>\n",
       "      <td>3635380</td>\n",
       "      <td>659417</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1253975.0</td>\n",
       "      <td>0</td>\n",
       "      <td>862</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>True</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>fr</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>26246 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        customer_id  street_id  structure_id  mcp_contact_id  fidelity  \\\n",
       "2             11005       1063           NaN             NaN         0   \n",
       "3             17663      12731           NaN             NaN         0   \n",
       "4             38100      12395           NaN             NaN         0   \n",
       "5            307036        139           NaN             NaN         0   \n",
       "6              2946       1063           NaN             NaN         0   \n",
       "...             ...        ...           ...             ...       ...   \n",
       "338933      3625705     648752           NaN       1253864.0         0   \n",
       "338954      3627626     636890           NaN       1253887.0         0   \n",
       "338959      3628124     653042           NaN       1253899.0         0   \n",
       "338986      3631189     648423           NaN       1253928.0         0   \n",
       "339039      3635380     659417           NaN       1253975.0         0   \n",
       "\n",
       "        tenant_id  is_partner  deleted_at  gender  is_email_true  ...  \\\n",
       "2             875       False         NaN       2          False  ...   \n",
       "3             875       False         NaN       0          False  ...   \n",
       "4             875       False         NaN       0           True  ...   \n",
       "5             875       False         NaN       2           True  ...   \n",
       "6             875       False         NaN       2          False  ...   \n",
       "...           ...         ...         ...     ...            ...  ...   \n",
       "338933        862       False         NaN       0           True  ...   \n",
       "338954        862       False         NaN       0           True  ...   \n",
       "338959        862       False         NaN       0           True  ...   \n",
       "338986        862       False         NaN       0           True  ...   \n",
       "339039        862       False         NaN       1           True  ...   \n",
       "\n",
       "        first_buying_date country  gender_label  gender_female  gender_male  \\\n",
       "2                     NaN      fr         other              0            0   \n",
       "3                     NaN      fr        female              1            0   \n",
       "4                     NaN      fr        female              1            0   \n",
       "5                     NaN     NaN         other              0            0   \n",
       "6                     NaN      fr         other              0            0   \n",
       "...                   ...     ...           ...            ...          ...   \n",
       "338933                NaN      fr        female              1            0   \n",
       "338954                NaN      fr        female              1            0   \n",
       "338959                NaN      fr        female              1            0   \n",
       "338986                NaN      fr        female              1            0   \n",
       "339039                NaN      fr          male              0            1   \n",
       "\n",
       "        gender_other  country_fr  has_tags  number_compagny  already_purchased  \n",
       "2                  1         1.0         0               10              False  \n",
       "3                  0         1.0         0               10              False  \n",
       "4                  0         1.0         0               10              False  \n",
       "5                  1         NaN         0               10              False  \n",
       "6                  1         1.0         0               10              False  \n",
       "...              ...         ...       ...              ...                ...  \n",
       "338933             0         1.0         0               14              False  \n",
       "338954             0         1.0         0               14              False  \n",
       "338959             0         1.0         0               14              False  \n",
       "338986             0         1.0         0               14              False  \n",
       "339039             0         1.0         0               14              False  \n",
       "\n",
       "[26246 rows x 30 columns]"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# attention, on a des cas où le client a pas de première date d'achat alors qu'il compte plusieurs achats\n",
    "# on peut donc avoir une date de première achat valant NaN non pas parce que l'individu n'a jamais acheté \n",
    "# mais simplement car elle n'est pas renseignée\n",
    "\n",
    "customerplus_clean_spectacle[(customerplus_clean_spectacle[\"already_purchased\"]==False) &\n",
    "(customerplus_clean_spectacle[\"purchase_count\"]>0)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "b5904039-a967-47d5-ba13-1b805bcd76ca",
   "metadata": {},
   "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>customer_id</th>\n",
       "      <th>street_id</th>\n",
       "      <th>structure_id</th>\n",
       "      <th>mcp_contact_id</th>\n",
       "      <th>fidelity</th>\n",
       "      <th>tenant_id</th>\n",
       "      <th>is_partner</th>\n",
       "      <th>deleted_at</th>\n",
       "      <th>gender</th>\n",
       "      <th>is_email_true</th>\n",
       "      <th>...</th>\n",
       "      <th>first_buying_date</th>\n",
       "      <th>country</th>\n",
       "      <th>gender_label</th>\n",
       "      <th>gender_female</th>\n",
       "      <th>gender_male</th>\n",
       "      <th>gender_other</th>\n",
       "      <th>country_fr</th>\n",
       "      <th>has_tags</th>\n",
       "      <th>number_compagny</th>\n",
       "      <th>already_purchased</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>0 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [customer_id, street_id, structure_id, mcp_contact_id, fidelity, tenant_id, is_partner, deleted_at, gender, is_email_true, opt_in, last_buying_date, max_price, ticket_sum, average_price, average_purchase_delay, average_price_basket, average_ticket_basket, total_price, purchase_count, first_buying_date, country, gender_label, gender_female, gender_male, gender_other, country_fr, has_tags, number_compagny, already_purchased]\n",
       "Index: []\n",
       "\n",
       "[0 rows x 30 columns]"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# cpdt, si un client a un nombre d'achats nul, il a bien une date de premier achat valant NaN, OK\n",
    "customerplus_clean_spectacle[(customerplus_clean_spectacle[\"already_purchased\"]) &\n",
    "(customerplus_clean_spectacle[\"purchase_count\"]==0)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "e940bfcf-29cc-4d4c-ae5e-e2a8cecf28af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "number_compagny  already_purchased\n",
       "10               False                0.234840\n",
       "                 True                 0.236236\n",
       "11               False                0.141746\n",
       "                 True                 0.002804\n",
       "12               False                0.485950\n",
       "                 True                 0.244779\n",
       "13               False                0.084057\n",
       "                 True                 0.177213\n",
       "14               False                0.885553\n",
       "                 True                 0.308859\n",
       "Name: opt_in, dtype: float64"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# différence de consentement aux campagnes de mails (opt in)\n",
    "\n",
    "# en se restreignant au personnes n'ayant pas acheté, on a quand même des individus acceptant d'être ciblés\n",
    "customerplus_clean_spectacle[customerplus_clean_spectacle[\"first_buying_date\"].isna()][\"opt_in\"].unique()\n",
    "\n",
    "# taux de consentement variés\n",
    "customerplus_clean_spectacle[\"already_purchased\"] = customerplus_clean_spectacle[\"purchase_count\"] > 0\n",
    "customerplus_clean_spectacle.groupby([\"number_compagny\", \"already_purchased\"])[\"opt_in\"].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "a5e79beb-9ba0-4c89-b084-e27ff0d65dcc",
   "metadata": {},
   "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>number_compagny</th>\n",
       "      <th>already_purchased</th>\n",
       "      <th>opt_in</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "      <td>0.234840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10</td>\n",
       "      <td>True</td>\n",
       "      <td>0.236236</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11</td>\n",
       "      <td>False</td>\n",
       "      <td>0.141746</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>11</td>\n",
       "      <td>True</td>\n",
       "      <td>0.002804</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>12</td>\n",
       "      <td>False</td>\n",
       "      <td>0.485950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>12</td>\n",
       "      <td>True</td>\n",
       "      <td>0.244779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>13</td>\n",
       "      <td>False</td>\n",
       "      <td>0.084057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>13</td>\n",
       "      <td>True</td>\n",
       "      <td>0.177213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "      <td>0.885553</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>14</td>\n",
       "      <td>True</td>\n",
       "      <td>0.308859</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   number_compagny  already_purchased    opt_in\n",
       "0               10              False  0.234840\n",
       "1               10               True  0.236236\n",
       "2               11              False  0.141746\n",
       "3               11               True  0.002804\n",
       "4               12              False  0.485950\n",
       "5               12               True  0.244779\n",
       "6               13              False  0.084057\n",
       "7               13               True  0.177213\n",
       "8               14              False  0.885553\n",
       "9               14               True  0.308859"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_graph = customerplus_clean_spectacle.groupby([\"number_compagny\", \"already_purchased\"])[\"opt_in\"].mean().reset_index()\n",
    "df_graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "5be56c41-7697-481a-84ea-f77a2041484b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 32416 characters]",
      "text/plain": [
       "<Figure size 1000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Création du barplot groupé\n",
    "fig, ax = plt.subplots(figsize=(10, 6))\n",
    "\n",
    "categories = df_graph[\"number_compagny\"].unique()\n",
    "bar_width = 0.35\n",
    "bar_positions = np.arange(len(categories))\n",
    "\n",
    "# Grouper les données par label et créer les barres groupées\n",
    "for label in df_graph[\"already_purchased\"].unique():\n",
    "    label_data = df_graph[df_graph['already_purchased'] == label]\n",
    "    values = [label_data[label_data['number_compagny'] == category]['opt_in'].values[0]*100 for category in categories]\n",
    "\n",
    "    label_printed = \"purchased\" if label else \"no purchase\"\n",
    "    ax.bar(bar_positions, values, bar_width, label=label_printed)\n",
    "\n",
    "    # Mise à jour des positions des barres pour le prochain groupe\n",
    "    bar_positions = [pos + bar_width for pos in bar_positions]\n",
    "\n",
    "# Ajout des étiquettes, de la légende, etc.\n",
    "ax.set_xlabel('Numero de compagnie')\n",
    "ax.set_ylabel('Part de consentement (%)')\n",
    "ax.set_title('Part de consentement au mailing selon les compagnies')\n",
    "ax.set_xticks([pos + bar_width / 2 for pos in np.arange(len(categories))])\n",
    "ax.set_xticklabels(categories)\n",
    "ax.legend()\n",
    "\n",
    "# Affichage du plot\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "32960530-cb46-4eeb-a6d2-1dcf5fb640d8",
   "metadata": {},
   "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>number_compagny</th>\n",
       "      <th>gender_male</th>\n",
       "      <th>gender_female</th>\n",
       "      <th>gender_other</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>0.181580</td>\n",
       "      <td>0.343837</td>\n",
       "      <td>0.474583</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11</td>\n",
       "      <td>0.179520</td>\n",
       "      <td>0.314443</td>\n",
       "      <td>0.506037</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12</td>\n",
       "      <td>0.346380</td>\n",
       "      <td>0.454036</td>\n",
       "      <td>0.199584</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13</td>\n",
       "      <td>0.318108</td>\n",
       "      <td>0.503092</td>\n",
       "      <td>0.178800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>14</td>\n",
       "      <td>0.331954</td>\n",
       "      <td>0.316181</td>\n",
       "      <td>0.351865</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   number_compagny  gender_male  gender_female  gender_other\n",
       "0               10     0.181580       0.343837      0.474583\n",
       "1               11     0.179520       0.314443      0.506037\n",
       "2               12     0.346380       0.454036      0.199584\n",
       "3               13     0.318108       0.503092      0.178800\n",
       "4               14     0.331954       0.316181      0.351865"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# genre \n",
    "\n",
    "company_genders = customerplus_clean_spectacle.groupby(\"number_compagny\")[[\"gender_male\", \"gender_female\", \"gender_other\"]].mean().reset_index()\n",
    "company_genders"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "1b4a49d7-7bfe-4e80-aa7e-c9c6d4bc46e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 30288 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Création du barplot\n",
    "plt.bar(company_genders[\"number_compagny\"], company_genders[\"gender_male\"], label = \"Homme\")\n",
    "plt.bar(company_genders[\"number_compagny\"], company_genders[\"gender_female\"], \n",
    "        bottom = company_genders[\"gender_male\"], label = \"Femme\")\n",
    "\n",
    "\n",
    "# Ajout de titres et d'étiquettes\n",
    "plt.xlabel('Company')\n",
    "plt.ylabel(\"Part de clients de chaque sexe\")\n",
    "plt.title(\"Sexe des clients de chaque compagnie de spectacle\")\n",
    "plt.legend()\n",
    "\n",
    "# Affichage du barplot\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "id": "ed6374e5-f36c-4f8e-9dba-602715b726f1",
   "metadata": {},
   "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>number_compagny</th>\n",
       "      <th>country_fr</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>0.996136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11</td>\n",
       "      <td>0.994838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12</td>\n",
       "      <td>0.002119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13</td>\n",
       "      <td>0.831795</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>14</td>\n",
       "      <td>0.993978</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   number_compagny  country_fr\n",
       "0               10    0.996136\n",
       "1               11    0.994838\n",
       "2               12    0.002119\n",
       "3               13    0.831795\n",
       "4               14    0.993978"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pays d'origine (France VS reste du monde)\n",
    "\n",
    "company_country_fr = customerplus_clean_spectacle.groupby(\"number_compagny\")[\"country_fr\"].mean().reset_index()\n",
    "company_country_fr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "id": "8d95cdd9-2ab3-4c9a-8442-bb9b98e0dd18",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 24844 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Création du barplot\n",
    "plt.bar(company_country_fr[\"number_compagny\"], company_country_fr[\"country_fr\"])\n",
    "\n",
    "# Ajout de titres et d'étiquettes\n",
    "plt.xlabel('Company')\n",
    "plt.ylabel(\"Part de clients français\")\n",
    "plt.title(\"Nationalité des clients de chaque compagnie de spectacle\")\n",
    "\n",
    "# Affichage du barplot\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ecfd112e-270a-4223-b80f-7e95e57d199d",
   "metadata": {},
   "source": [
    "### 2. campaigns_information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "id": "b37e7ddf-321a-4ebe-9742-9e760a541d29",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nombre de lignes de la table :  688953\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "customer_id                 0\n",
       "nb_campaigns                0\n",
       "nb_campaigns_opened         0\n",
       "time_to_open           301495\n",
       "number_compagny             0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 189,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# nombre de nan\n",
    "print(\"Nombre de lignes de la table : \",campaigns_information_spectacle.shape[0])\n",
    "campaigns_information_spectacle.isna().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "id": "de1ecaac-25bb-4853-b8ab-3ef2ca6917ed",
   "metadata": {},
   "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>customer_id</th>\n",
       "      <th>nb_campaigns</th>\n",
       "      <th>nb_campaigns_opened</th>\n",
       "      <th>time_to_open</th>\n",
       "      <th>number_compagny</th>\n",
       "      <th>no_campaign_opened</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>29</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaT</td>\n",
       "      <td>10</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>37</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaT</td>\n",
       "      <td>10</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>39</td>\n",
       "      <td>4</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0 days 05:16:38</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>41</td>\n",
       "      <td>4</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0 days 01:12:29</td>\n",
       "      <td>10</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>44</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaT</td>\n",
       "      <td>10</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>254699</th>\n",
       "      <td>6837769</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0 days 23:42:15</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>254700</th>\n",
       "      <td>6875038</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaT</td>\n",
       "      <td>14</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>254701</th>\n",
       "      <td>6875066</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaT</td>\n",
       "      <td>14</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>254702</th>\n",
       "      <td>6875099</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaT</td>\n",
       "      <td>14</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>254703</th>\n",
       "      <td>6875143</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0 days 01:17:01</td>\n",
       "      <td>14</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>688953 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        customer_id  nb_campaigns  nb_campaigns_opened    time_to_open  \\\n",
       "0                29             4                  0.0             NaT   \n",
       "1                37             3                  0.0             NaT   \n",
       "2                39             4                  1.0 0 days 05:16:38   \n",
       "3                41             4                  1.0 0 days 01:12:29   \n",
       "4                44             4                  0.0             NaT   \n",
       "...             ...           ...                  ...             ...   \n",
       "254699      6837769             1                  1.0 0 days 23:42:15   \n",
       "254700      6875038             1                  0.0             NaT   \n",
       "254701      6875066             1                  0.0             NaT   \n",
       "254702      6875099             1                  0.0             NaT   \n",
       "254703      6875143             1                  1.0 0 days 01:17:01   \n",
       "\n",
       "        number_compagny  no_campaign_opened  \n",
       "0                    10                True  \n",
       "1                    10                True  \n",
       "2                    10               False  \n",
       "3                    10               False  \n",
       "4                    10                True  \n",
       "...                 ...                 ...  \n",
       "254699               14               False  \n",
       "254700               14                True  \n",
       "254701               14                True  \n",
       "254702               14                True  \n",
       "254703               14               False  \n",
       "\n",
       "[688953 rows x 6 columns]"
      ]
     },
     "execution_count": 192,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# part de clients n'ouvrant jamais les mails par compagnie\n",
    "\n",
    "campaigns_information_spectacle[\"no_campaign_opened\"] = pd.isna(campaigns_information_spectacle[\"time_to_open\"])\n",
    "campaigns_information_spectacle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "id": "b5a0060f-a9dd-435b-844f-b24674b8bc27",
   "metadata": {},
   "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>number_compagny</th>\n",
       "      <th>no_campaign_opened</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>0.605656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11</td>\n",
       "      <td>0.294001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12</td>\n",
       "      <td>0.475719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13</td>\n",
       "      <td>0.353820</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>14</td>\n",
       "      <td>0.428148</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   number_compagny  no_campaign_opened\n",
       "0               10            0.605656\n",
       "1               11            0.294001\n",
       "2               12            0.475719\n",
       "3               13            0.353820\n",
       "4               14            0.428148"
      ]
     },
     "execution_count": 197,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "company_lazy_customers = campaigns_information_spectacle.groupby(\"number_compagny\")[\"no_campaign_opened\"].mean().reset_index()\n",
    "company_lazy_customers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "id": "788c90e0-f13a-4804-ace7-e5159fddd7fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 31696 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Création du barplot\n",
    "plt.bar(company_lazy_customers[\"number_compagny\"], company_lazy_customers[\"no_campaign_opened\"])\n",
    "\n",
    "# Ajout de titres et d'étiquettes\n",
    "plt.xlabel('Company')\n",
    "plt.ylabel(\"Part de clients n'ayant ouvert aucun mail\")\n",
    "plt.title(\"Part de clients n'ayant ouvert aucun mail pour les compagnies de spectacle\")\n",
    "\n",
    "# Affichage du barplot\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "id": "c48015c2-6451-4089-93b7-6d55d3b2e553",
   "metadata": {},
   "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>number_compagny</th>\n",
       "      <th>nb_campaigns</th>\n",
       "      <th>nb_campaigns_opened</th>\n",
       "      <th>ratio_campaigns_opened</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>734772</td>\n",
       "      <td>126151.0</td>\n",
       "      <td>0.171687</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11</td>\n",
       "      <td>342396</td>\n",
       "      <td>129833.0</td>\n",
       "      <td>0.379190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12</td>\n",
       "      <td>3168123</td>\n",
       "      <td>810722.0</td>\n",
       "      <td>0.255900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13</td>\n",
       "      <td>3218569</td>\n",
       "      <td>793581.0</td>\n",
       "      <td>0.246563</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>14</td>\n",
       "      <td>2427043</td>\n",
       "      <td>723846.0</td>\n",
       "      <td>0.298242</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   number_compagny  nb_campaigns  nb_campaigns_opened  ratio_campaigns_opened\n",
       "0               10        734772             126151.0                0.171687\n",
       "1               11        342396             129833.0                0.379190\n",
       "2               12       3168123             810722.0                0.255900\n",
       "3               13       3218569             793581.0                0.246563\n",
       "4               14       2427043             723846.0                0.298242"
      ]
     },
     "execution_count": 203,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# taux d'ouverture des campaigns\n",
    "\n",
    "company_campaigns_stats = campaigns_information_spectacle.groupby(\"number_compagny\")[[\"nb_campaigns\", \"nb_campaigns_opened\"]].sum().reset_index()\n",
    "company_campaigns_stats[\"ratio_campaigns_opened\"] = company_campaigns_stats[\"nb_campaigns_opened\"]  / company_campaigns_stats[\"nb_campaigns\"]\n",
    "company_campaigns_stats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "id": "d06ab865-4832-4fe9-918b-e5ff72bebee4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 27108 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Création du barplot\n",
    "plt.bar(company_campaigns_stats[\"number_compagny\"], 100 * company_campaigns_stats[\"ratio_campaigns_opened\"])\n",
    "\n",
    "# Ajout de titres et d'étiquettes\n",
    "plt.xlabel('Company')\n",
    "plt.ylabel(\"Taux d'ouverture (%)\")\n",
    "plt.title(\"Taux d'ouverture des campagnes de mails pour les compagnies de spectacle\")\n",
    "\n",
    "# Affichage du barplot\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "id": "5c37e063-a717-4a8c-828e-b386b87e8409",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 31384 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# création d'un barplot permettant de visualiser les 2 indicateurs sur le même graphique\n",
    "\n",
    "# Création du premier barplot\n",
    "plt.bar(company_campaigns_stats[\"number_compagny\"], 100 * company_campaigns_stats[\"ratio_campaigns_opened\"],\n",
    "       label = \"taux d'ouverture\", alpha = 0.7)\n",
    "\n",
    "# Création du deuxième barplot à côté du premier\n",
    "bar_width = 0.4  # Largeur des barres\n",
    "indices2 = company_campaigns_stats[\"number_compagny\"] + bar_width\n",
    "plt.bar(indices2, 100 * (1 - company_lazy_customers[\"no_campaign_opened\"]), \n",
    "        label='Part de clients ouvrant des mails', alpha=0.7, width=bar_width)\n",
    "\n",
    "# Ajout des étiquettes et de la légende\n",
    "plt.xlabel('Compagnie')\n",
    "plt.ylabel('Taux (%)')\n",
    "plt.title('Lien entre taux d ouverture des mails et nombre de clients actifs')\n",
    "plt.legend()\n",
    "\n",
    "# Affichage du graphique\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "783f6fb2-5f26-42a9-a22d-f4ece44bfaf2",
   "metadata": {},
   "source": [
    "### 3. products_purchased_reduced"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "74534ded-8121-43fb-8cf8-af353bed2c77",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nombre de lignes de la table :  764880\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "customer_id              0\n",
       "nb_tickets               0\n",
       "nb_purchases             0\n",
       "total_amount             0\n",
       "nb_suppliers             0\n",
       "vente_internet_max       0\n",
       "purchase_date_min        0\n",
       "purchase_date_max        0\n",
       "time_between_purchase    0\n",
       "nb_tickets_internet      0\n",
       "number_compagny          0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# nombre de nan\n",
    "print(\"Nombre de lignes de la table : \",products_purchased_reduced_spectacle.shape[0])\n",
    "products_purchased_reduced_spectacle.isna().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "d64979ba-fccf-45f2-8a15-40ef1b49c74f",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_430/3239820253.py:6: DtypeWarning: Columns (39) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  dataset_train = pd.read_csv(file_in, sep=\",\")\n"
     ]
    }
   ],
   "source": [
    "#base d'entrainement\n",
    "\n",
    "#FILE_PATH_S3='projet-bdc2324-team1/Generalization/musique/Train_test/dataset_train14.csv'\n",
    "\n",
    "#with fs.open(FILE_PATH_S3, mode=\"rb\") as file_in:\n",
    "    #dataset_train = pd.read_csv(file_in, sep=\",\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "635d60cd-2dbc-49da-b0f4-94e16667882f",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Creation de la variable dependante fictive: 1 si l'individu a effectué un achat au cours de la periode de train et 0 sinon\n",
    "\n",
    "#dataset_train_modif=dataset_train\n",
    "\n",
    "#dataset_train_modif[\"y_purchase_fictive\"]=np.random.randint(2, size=dataset_train_modif.shape[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "ea63e5d6-70f9-4685-8b08-673a47108954",
   "metadata": {},
   "outputs": [],
   "source": [
    "#dataset_train_modif[\"y_purchase_fictive\"].value_counts(normalize=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "98f7645f-ffe6-4d7b-8032-15e65f36af87",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "#dataset_train_modif[\"y_purchase_fictive\"]=dataset_train_modif[\"y_purchase_fictive\"].replace([0,1],[\"Purchase_train\",\"no_purchase_train\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "6db089d5-5517-4aee-a5fd-53f20ae3f0d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "#importation librairies\n",
    "import warnings\n",
    "warnings.simplefilter(\"ignore\")\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import statsmodels\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "from scipy.stats import shapiro\n",
    "from numpy.random import randn\n",
    "import scipy.stats as st\n",
    "%matplotlib inline\n",
    "\n",
    "#col_purchase=[\"nb_tickets\",\"nb_purchases\",\"total_amount\",\"nb_suppliers\",\"time_between_purchase\",\"nb_tickets_internet\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c532f884-3f44-4ce7-8924-9b4542bc3c10",
   "metadata": {},
   "outputs": [],
   "source": [
    "#histogrames des variable quantitatives\n",
    "col_purchase=[\"nb_tickets\",\"nb_purchases\",\"total_amount\",\"nb_suppliers\",\"time_between_purchase\",\"nb_tickets_internet\"]\n",
    "for col in col_purchase:\n",
    "    plt.figure()\n",
    "    sns.histplot(products_purchased_reduced_spectacle[col], kde=True, color='red')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "eb6355e0-3f8c-47d9-a5ee-d349040dcf51",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, \"Boite à moustache du chiffre d'affaire selon les compagnies de spectacles\")"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 28512 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#repartition Chiffre d'affaire selon les compagnie de spectacle\n",
    "\n",
    "sns.boxplot(data=products_purchased_reduced_spectacle, y=\"total_amount\",x=\"number_compagny\",showfliers=False,showmeans=True)\n",
    "plt.title(\"Boite à moustache du chiffre d'affaire selon les compagnies de spectacles\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "aacf2c34-f7ea-4d6e-935b-c5db01f03bbe",
   "metadata": {},
   "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>number_compagny</th>\n",
       "      <th>nb_tickets</th>\n",
       "      <th>nb_tickets_internet</th>\n",
       "      <th>Taux_ticket_internet</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>492314</td>\n",
       "      <td>126262.0</td>\n",
       "      <td>25.646640</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11</td>\n",
       "      <td>318969</td>\n",
       "      <td>16348.0</td>\n",
       "      <td>5.125263</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12</td>\n",
       "      <td>591028</td>\n",
       "      <td>42045.0</td>\n",
       "      <td>7.113876</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13</td>\n",
       "      <td>7024227</td>\n",
       "      <td>1247482.0</td>\n",
       "      <td>17.759705</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>14</td>\n",
       "      <td>335741</td>\n",
       "      <td>125638.0</td>\n",
       "      <td>37.421107</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   number_compagny  nb_tickets  nb_tickets_internet  Taux_ticket_internet\n",
       "0               10      492314             126262.0             25.646640\n",
       "1               11      318969              16348.0              5.125263\n",
       "2               12      591028              42045.0              7.113876\n",
       "3               13     7024227            1247482.0             17.759705\n",
       "4               14      335741             125638.0             37.421107"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Taux de ticket payé par internet selon les compagnies\n",
    "\n",
    "purchase_spectacle = products_purchased_reduced_spectacle.groupby(\"number_compagny\")[[\"nb_tickets\", \"nb_tickets_internet\"]].sum().reset_index()\n",
    "purchase_spectacle[\"Taux_ticket_internet\"] = purchase_spectacle[\"nb_tickets_internet\"]*100 / purchase_spectacle[\"nb_tickets\"]\n",
    "purchase_spectacle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "f71bb53d-724b-454d-8743-305d20eec2b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 28928 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Création du barplot\n",
    "plt.bar(purchase_spectacle[\"number_compagny\"],  purchase_spectacle[\"Taux_ticket_internet\"])\n",
    "\n",
    "# Ajout de titres et d'étiquettes\n",
    "plt.xlabel('Company')\n",
    "plt.ylabel(\"Taux d'achat de tickets en ligne (%)\")\n",
    "plt.title(\"Taux d'achat des tickets en ligne selon les compagnies de spectacle\")\n",
    "\n",
    "# Affichage du barplot\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "254875ac-95e4-44fa-9f02-6cec144e4bde",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "la p-value associé à la stat de fisher est  superieure à 5% donc il n y a pas de lien entre les entreprise et  le taux de ticket  acheté en ligne\n"
     ]
    }
   ],
   "source": [
    "#test anova entre les entreprise de spectacle et taux d'achat de ticket en ligne\n",
    "import statsmodels.api as sm\n",
    "from statsmodels.formula.api import ols\n",
    "model = ols('Taux_ticket_internet ~ number_compagny', data=purchase_spectacle).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print(\"la p-value associé à la stat de fisher est  superieure à 5% donc il n y a pas de lien entre les entreprise et  le taux de ticket  acheté en ligne\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "59a95248-0261-4970-9e91-e43d50cf4d69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Boite à moustache du temps ecoulés entre le premier et le dernier achat selon les compagnies de spectacles')"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 38360 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#repartion Chiffre d'affaire selon le numero de la compagnie\n",
    "\n",
    "sns.boxplot(data=products_purchased_reduced_spectacle, y=\"time_between_purchase\",x=\"number_compagny\",showfliers=False,showmeans=True)\n",
    "plt.title(\"Boite à moustache du temps ecoulés entre le premier et le dernier achat selon les compagnies de spectacles\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58cbe8a5-3899-4aa3-91ab-48bed9124fbd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "58f49748-e55f-4d1b-b58b-102d02a9e0eb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                       sum_sq        df             F  PR(>F)\n",
      "number_compagny  4.108441e+09       1.0  23548.336165     0.0\n",
      "Residual         1.334471e+11  764878.0           NaN     NaN la p-value associé à la stat de fisher est  inferieure à 5% donc il y a un lien entre les entreprise et  le temps écoulés  entre le premier et le dernier achat\n"
     ]
    }
   ],
   "source": [
    "#test anova entre les entreprise de spectacle et time_between_purchase\n",
    "import statsmodels.api as sm\n",
    "from statsmodels.formula.api import ols\n",
    "model = ols('time_between_purchase ~ number_compagny', data=products_purchased_reduced_spectacle).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "anova_table\n",
    "print(anova_table,\"la p-value associé à la stat de fisher est  inferieure à 5% donc il y a un lien entre les entreprise et  le temps écoulés  entre le premier et le dernier achat\" )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33ef5773-a09d-4b8c-918f-1b64a9790422",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "b9e84af4-a02b-4f83-81ae-b7a73475d060",
   "metadata": {},
   "source": [
    "### 4. target_information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "id": "2867eceb-1f72-406c-adc2-adfedcaf60e6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nombre de lignes de la table :  6240166\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "id                       0\n",
       "customer_id              0\n",
       "target_name              0\n",
       "target_type_is_import    0\n",
       "target_type_name         0\n",
       "number_compagny          0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 222,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# nombre de nan\n",
    "print(\"Nombre de lignes de la table : \",target_information_spectacle.shape[0])\n",
    "target_information_spectacle.isna().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "985b6403-3c75-420e-a4a4-d3045213e9ef",
   "metadata": {},
   "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>id</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>target_name</th>\n",
       "      <th>target_type_is_import</th>\n",
       "      <th>target_type_name</th>\n",
       "      <th>number_compagny</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1165098</td>\n",
       "      <td>618562</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1165100</td>\n",
       "      <td>618559</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1165101</td>\n",
       "      <td>618561</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1165102</td>\n",
       "      <td>618560</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1165103</td>\n",
       "      <td>618558</td>\n",
       "      <td>Newsletter mensuelle</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>779653</th>\n",
       "      <td>4207082</td>\n",
       "      <td>6764876</td>\n",
       "      <td>INSCRIPTION NL VOYAGES HUMA</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>779654</th>\n",
       "      <td>4207083</td>\n",
       "      <td>6764877</td>\n",
       "      <td>Inscriptions newsletters (depuis 2019)</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>779655</th>\n",
       "      <td>4207084</td>\n",
       "      <td>6801322</td>\n",
       "      <td>Inscriptions newsletters (depuis 2019)</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>779656</th>\n",
       "      <td>4207085</td>\n",
       "      <td>6837768</td>\n",
       "      <td>Inscriptions newsletters (depuis 2019)</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>779657</th>\n",
       "      <td>4207086</td>\n",
       "      <td>6837769</td>\n",
       "      <td>Inscriptions newsletters (depuis 2019)</td>\n",
       "      <td>False</td>\n",
       "      <td>manual_static_filter</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>6240166 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             id  customer_id                             target_name  \\\n",
       "0       1165098       618562                    Newsletter mensuelle   \n",
       "1       1165100       618559                    Newsletter mensuelle   \n",
       "2       1165101       618561                    Newsletter mensuelle   \n",
       "3       1165102       618560                    Newsletter mensuelle   \n",
       "4       1165103       618558                    Newsletter mensuelle   \n",
       "...         ...          ...                                     ...   \n",
       "779653  4207082      6764876             INSCRIPTION NL VOYAGES HUMA   \n",
       "779654  4207083      6764877  Inscriptions newsletters (depuis 2019)   \n",
       "779655  4207084      6801322  Inscriptions newsletters (depuis 2019)   \n",
       "779656  4207085      6837768  Inscriptions newsletters (depuis 2019)   \n",
       "779657  4207086      6837769  Inscriptions newsletters (depuis 2019)   \n",
       "\n",
       "        target_type_is_import      target_type_name  number_compagny  \n",
       "0                       False  manual_static_filter               10  \n",
       "1                       False  manual_static_filter               10  \n",
       "2                       False  manual_static_filter               10  \n",
       "3                       False  manual_static_filter               10  \n",
       "4                       False  manual_static_filter               10  \n",
       "...                       ...                   ...              ...  \n",
       "779653                  False  manual_static_filter               14  \n",
       "779654                  False  manual_static_filter               14  \n",
       "779655                  False  manual_static_filter               14  \n",
       "779656                  False  manual_static_filter               14  \n",
       "779657                  False  manual_static_filter               14  \n",
       "\n",
       "[6240166 rows x 6 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "target_information_spectacle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "93a8ae1f-6fbd-4210-a857-728ae472d1c5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "904cbf32-77b6-49dd-a96c-9e7e5a0175c3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
