{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from matplotlib import pyplot\n",
    "\n",
    "from scipy.stats import shapiro\n",
    "from scipy.stats import normaltest\n",
    "from scipy.stats import anderson\n",
    "from scipy.stats import chi2_contingency\n",
    "from scipy.stats import chi2\n",
    "from scipy.stats import ttest_ind\n",
    "\n",
    "import statsmodels.api as sm\n",
    "from statsmodels.formula.api import ols\n",
    "from statsmodels.stats.multicomp import pairwise_tukeyhsd\n",
    "from statsmodels.graphics.gofplots import qqplot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#import the data\n",
    "salesdf = pd.read_csv(\"sales.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "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>Invoice ID</th>\n",
       "      <th>Branch</th>\n",
       "      <th>City</th>\n",
       "      <th>Customer type</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Product line</th>\n",
       "      <th>Unit price</th>\n",
       "      <th>Quantity</th>\n",
       "      <th>Tax 5%</th>\n",
       "      <th>Total</th>\n",
       "      <th>Date</th>\n",
       "      <th>Time</th>\n",
       "      <th>Payment</th>\n",
       "      <th>cogs</th>\n",
       "      <th>gross margin percentage</th>\n",
       "      <th>gross income</th>\n",
       "      <th>Rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>750-67-8428</td>\n",
       "      <td>A</td>\n",
       "      <td>Yangon</td>\n",
       "      <td>Member</td>\n",
       "      <td>Female</td>\n",
       "      <td>Health and beauty</td>\n",
       "      <td>74.69</td>\n",
       "      <td>7</td>\n",
       "      <td>26.1415</td>\n",
       "      <td>548.9715</td>\n",
       "      <td>1/5/2019</td>\n",
       "      <td>13:08</td>\n",
       "      <td>Ewallet</td>\n",
       "      <td>522.83</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>26.1415</td>\n",
       "      <td>9.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>226-31-3081</td>\n",
       "      <td>C</td>\n",
       "      <td>Naypyitaw</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Female</td>\n",
       "      <td>Electronic accessories</td>\n",
       "      <td>15.28</td>\n",
       "      <td>5</td>\n",
       "      <td>3.8200</td>\n",
       "      <td>80.2200</td>\n",
       "      <td>3/8/2019</td>\n",
       "      <td>10:29</td>\n",
       "      <td>Cash</td>\n",
       "      <td>76.40</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>3.8200</td>\n",
       "      <td>9.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>631-41-3108</td>\n",
       "      <td>A</td>\n",
       "      <td>Yangon</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Male</td>\n",
       "      <td>Home and lifestyle</td>\n",
       "      <td>46.33</td>\n",
       "      <td>7</td>\n",
       "      <td>16.2155</td>\n",
       "      <td>340.5255</td>\n",
       "      <td>3/3/2019</td>\n",
       "      <td>13:23</td>\n",
       "      <td>Credit card</td>\n",
       "      <td>324.31</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>16.2155</td>\n",
       "      <td>7.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>123-19-1176</td>\n",
       "      <td>A</td>\n",
       "      <td>Yangon</td>\n",
       "      <td>Member</td>\n",
       "      <td>Male</td>\n",
       "      <td>Health and beauty</td>\n",
       "      <td>58.22</td>\n",
       "      <td>8</td>\n",
       "      <td>23.2880</td>\n",
       "      <td>489.0480</td>\n",
       "      <td>1/27/2019</td>\n",
       "      <td>20:33</td>\n",
       "      <td>Ewallet</td>\n",
       "      <td>465.76</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>23.2880</td>\n",
       "      <td>8.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>373-73-7910</td>\n",
       "      <td>A</td>\n",
       "      <td>Yangon</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Male</td>\n",
       "      <td>Sports and travel</td>\n",
       "      <td>86.31</td>\n",
       "      <td>7</td>\n",
       "      <td>30.2085</td>\n",
       "      <td>634.3785</td>\n",
       "      <td>2/8/2019</td>\n",
       "      <td>10:37</td>\n",
       "      <td>Ewallet</td>\n",
       "      <td>604.17</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>30.2085</td>\n",
       "      <td>5.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>699-14-3026</td>\n",
       "      <td>C</td>\n",
       "      <td>Naypyitaw</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Male</td>\n",
       "      <td>Electronic accessories</td>\n",
       "      <td>85.39</td>\n",
       "      <td>7</td>\n",
       "      <td>29.8865</td>\n",
       "      <td>627.6165</td>\n",
       "      <td>3/25/2019</td>\n",
       "      <td>18:30</td>\n",
       "      <td>Ewallet</td>\n",
       "      <td>597.73</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>29.8865</td>\n",
       "      <td>4.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>355-53-5943</td>\n",
       "      <td>A</td>\n",
       "      <td>Yangon</td>\n",
       "      <td>Member</td>\n",
       "      <td>Female</td>\n",
       "      <td>Electronic accessories</td>\n",
       "      <td>68.84</td>\n",
       "      <td>6</td>\n",
       "      <td>20.6520</td>\n",
       "      <td>433.6920</td>\n",
       "      <td>2/25/2019</td>\n",
       "      <td>14:36</td>\n",
       "      <td>Ewallet</td>\n",
       "      <td>413.04</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>20.6520</td>\n",
       "      <td>5.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>315-22-5665</td>\n",
       "      <td>C</td>\n",
       "      <td>Naypyitaw</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Female</td>\n",
       "      <td>Home and lifestyle</td>\n",
       "      <td>73.56</td>\n",
       "      <td>10</td>\n",
       "      <td>36.7800</td>\n",
       "      <td>772.3800</td>\n",
       "      <td>2/24/2019</td>\n",
       "      <td>11:38</td>\n",
       "      <td>Ewallet</td>\n",
       "      <td>735.60</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>36.7800</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>665-32-9167</td>\n",
       "      <td>A</td>\n",
       "      <td>Yangon</td>\n",
       "      <td>Member</td>\n",
       "      <td>Female</td>\n",
       "      <td>Health and beauty</td>\n",
       "      <td>36.26</td>\n",
       "      <td>2</td>\n",
       "      <td>3.6260</td>\n",
       "      <td>76.1460</td>\n",
       "      <td>1/10/2019</td>\n",
       "      <td>17:15</td>\n",
       "      <td>Credit card</td>\n",
       "      <td>72.52</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>3.6260</td>\n",
       "      <td>7.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>692-92-5582</td>\n",
       "      <td>B</td>\n",
       "      <td>Mandalay</td>\n",
       "      <td>Member</td>\n",
       "      <td>Female</td>\n",
       "      <td>Food and beverages</td>\n",
       "      <td>54.84</td>\n",
       "      <td>3</td>\n",
       "      <td>8.2260</td>\n",
       "      <td>172.7460</td>\n",
       "      <td>2/20/2019</td>\n",
       "      <td>13:27</td>\n",
       "      <td>Credit card</td>\n",
       "      <td>164.52</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>8.2260</td>\n",
       "      <td>5.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>351-62-0822</td>\n",
       "      <td>B</td>\n",
       "      <td>Mandalay</td>\n",
       "      <td>Member</td>\n",
       "      <td>Female</td>\n",
       "      <td>Fashion accessories</td>\n",
       "      <td>14.48</td>\n",
       "      <td>4</td>\n",
       "      <td>2.8960</td>\n",
       "      <td>60.8160</td>\n",
       "      <td>2/6/2019</td>\n",
       "      <td>18:07</td>\n",
       "      <td>Ewallet</td>\n",
       "      <td>57.92</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>2.8960</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>529-56-3974</td>\n",
       "      <td>B</td>\n",
       "      <td>Mandalay</td>\n",
       "      <td>Member</td>\n",
       "      <td>Male</td>\n",
       "      <td>Electronic accessories</td>\n",
       "      <td>25.51</td>\n",
       "      <td>4</td>\n",
       "      <td>5.1020</td>\n",
       "      <td>107.1420</td>\n",
       "      <td>3/9/2019</td>\n",
       "      <td>17:03</td>\n",
       "      <td>Cash</td>\n",
       "      <td>102.04</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>5.1020</td>\n",
       "      <td>6.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>365-64-0515</td>\n",
       "      <td>A</td>\n",
       "      <td>Yangon</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Female</td>\n",
       "      <td>Electronic accessories</td>\n",
       "      <td>46.95</td>\n",
       "      <td>5</td>\n",
       "      <td>11.7375</td>\n",
       "      <td>246.4875</td>\n",
       "      <td>2/12/2019</td>\n",
       "      <td>10:25</td>\n",
       "      <td>Ewallet</td>\n",
       "      <td>234.75</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>11.7375</td>\n",
       "      <td>7.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>252-56-2699</td>\n",
       "      <td>A</td>\n",
       "      <td>Yangon</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Male</td>\n",
       "      <td>Food and beverages</td>\n",
       "      <td>43.19</td>\n",
       "      <td>10</td>\n",
       "      <td>21.5950</td>\n",
       "      <td>453.4950</td>\n",
       "      <td>2/7/2019</td>\n",
       "      <td>16:48</td>\n",
       "      <td>Ewallet</td>\n",
       "      <td>431.90</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>21.5950</td>\n",
       "      <td>8.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>829-34-3910</td>\n",
       "      <td>A</td>\n",
       "      <td>Yangon</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Female</td>\n",
       "      <td>Health and beauty</td>\n",
       "      <td>71.38</td>\n",
       "      <td>10</td>\n",
       "      <td>35.6900</td>\n",
       "      <td>749.4900</td>\n",
       "      <td>3/29/2019</td>\n",
       "      <td>19:21</td>\n",
       "      <td>Cash</td>\n",
       "      <td>713.80</td>\n",
       "      <td>4.761905</td>\n",
       "      <td>35.6900</td>\n",
       "      <td>5.7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Invoice ID Branch       City Customer type  Gender  \\\n",
       "0   750-67-8428      A     Yangon        Member  Female   \n",
       "1   226-31-3081      C  Naypyitaw        Normal  Female   \n",
       "2   631-41-3108      A     Yangon        Normal    Male   \n",
       "3   123-19-1176      A     Yangon        Member    Male   \n",
       "4   373-73-7910      A     Yangon        Normal    Male   \n",
       "5   699-14-3026      C  Naypyitaw        Normal    Male   \n",
       "6   355-53-5943      A     Yangon        Member  Female   \n",
       "7   315-22-5665      C  Naypyitaw        Normal  Female   \n",
       "8   665-32-9167      A     Yangon        Member  Female   \n",
       "9   692-92-5582      B   Mandalay        Member  Female   \n",
       "10  351-62-0822      B   Mandalay        Member  Female   \n",
       "11  529-56-3974      B   Mandalay        Member    Male   \n",
       "12  365-64-0515      A     Yangon        Normal  Female   \n",
       "13  252-56-2699      A     Yangon        Normal    Male   \n",
       "14  829-34-3910      A     Yangon        Normal  Female   \n",
       "\n",
       "              Product line  Unit price  Quantity   Tax 5%     Total  \\\n",
       "0        Health and beauty       74.69         7  26.1415  548.9715   \n",
       "1   Electronic accessories       15.28         5   3.8200   80.2200   \n",
       "2       Home and lifestyle       46.33         7  16.2155  340.5255   \n",
       "3        Health and beauty       58.22         8  23.2880  489.0480   \n",
       "4        Sports and travel       86.31         7  30.2085  634.3785   \n",
       "5   Electronic accessories       85.39         7  29.8865  627.6165   \n",
       "6   Electronic accessories       68.84         6  20.6520  433.6920   \n",
       "7       Home and lifestyle       73.56        10  36.7800  772.3800   \n",
       "8        Health and beauty       36.26         2   3.6260   76.1460   \n",
       "9       Food and beverages       54.84         3   8.2260  172.7460   \n",
       "10     Fashion accessories       14.48         4   2.8960   60.8160   \n",
       "11  Electronic accessories       25.51         4   5.1020  107.1420   \n",
       "12  Electronic accessories       46.95         5  11.7375  246.4875   \n",
       "13      Food and beverages       43.19        10  21.5950  453.4950   \n",
       "14       Health and beauty       71.38        10  35.6900  749.4900   \n",
       "\n",
       "         Date   Time      Payment    cogs  gross margin percentage  \\\n",
       "0    1/5/2019  13:08      Ewallet  522.83                 4.761905   \n",
       "1    3/8/2019  10:29         Cash   76.40                 4.761905   \n",
       "2    3/3/2019  13:23  Credit card  324.31                 4.761905   \n",
       "3   1/27/2019  20:33      Ewallet  465.76                 4.761905   \n",
       "4    2/8/2019  10:37      Ewallet  604.17                 4.761905   \n",
       "5   3/25/2019  18:30      Ewallet  597.73                 4.761905   \n",
       "6   2/25/2019  14:36      Ewallet  413.04                 4.761905   \n",
       "7   2/24/2019  11:38      Ewallet  735.60                 4.761905   \n",
       "8   1/10/2019  17:15  Credit card   72.52                 4.761905   \n",
       "9   2/20/2019  13:27  Credit card  164.52                 4.761905   \n",
       "10   2/6/2019  18:07      Ewallet   57.92                 4.761905   \n",
       "11   3/9/2019  17:03         Cash  102.04                 4.761905   \n",
       "12  2/12/2019  10:25      Ewallet  234.75                 4.761905   \n",
       "13   2/7/2019  16:48      Ewallet  431.90                 4.761905   \n",
       "14  3/29/2019  19:21         Cash  713.80                 4.761905   \n",
       "\n",
       "    gross income  Rating  \n",
       "0        26.1415     9.1  \n",
       "1         3.8200     9.6  \n",
       "2        16.2155     7.4  \n",
       "3        23.2880     8.4  \n",
       "4        30.2085     5.3  \n",
       "5        29.8865     4.1  \n",
       "6        20.6520     5.8  \n",
       "7        36.7800     8.0  \n",
       "8         3.6260     7.2  \n",
       "9         8.2260     5.9  \n",
       "10        2.8960     4.5  \n",
       "11        5.1020     6.8  \n",
       "12       11.7375     7.1  \n",
       "13       21.5950     8.2  \n",
       "14       35.6900     5.7  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "salesdf.head(15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Invoice ID                 0\n",
       "Branch                     0\n",
       "City                       0\n",
       "Customer type              0\n",
       "Gender                     0\n",
       "Product line               0\n",
       "Unit price                 0\n",
       "Quantity                   0\n",
       "Tax 5%                     0\n",
       "Total                      0\n",
       "Date                       0\n",
       "Time                       0\n",
       "Payment                    0\n",
       "cogs                       0\n",
       "gross margin percentage    0\n",
       "gross income               0\n",
       "Rating                     0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "salesdf.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Invoice ID                  object\n",
       "Branch                      object\n",
       "City                        object\n",
       "Customer type               object\n",
       "Gender                      object\n",
       "Product line                object\n",
       "Unit price                 float64\n",
       "Quantity                     int64\n",
       "Tax 5%                     float64\n",
       "Total                      float64\n",
       "Date                        object\n",
       "Time                        object\n",
       "Payment                     object\n",
       "cogs                       float64\n",
       "gross margin percentage    float64\n",
       "gross income               float64\n",
       "Rating                     float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "salesdf.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Avg. Total Sales:   322.96674900000005\n",
      "Avg. Gross Income:   15.379369000000002\n",
      "(Total Sales, Gross Income) => t-value=39.513367637859865, p-value=8.149841030240183e-253\n"
     ]
    }
   ],
   "source": [
    "#t-test significant difference between sales and income?)\n",
    "print(\"Avg. Total Sales:  \", salesdf['Total'].mean())\n",
    "print(\"Avg. Gross Income:  \", salesdf['gross income'].mean())\n",
    "t_val, p_val = ttest_ind(salesdf['Total'], salesdf['gross income'])\n",
    "print(\"(Total Sales, Gross Income) => t-value=%s, p-value=%s\" % (str(t_val), str(p_val)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Avg. Total Sales:   322.96674900000005\n",
      "Avg. COGS:   307.58738000000034\n",
      "(Total Sales, COGS) => t-value=1.4322775554073317, p-value=0.1522208279559139\n"
     ]
    }
   ],
   "source": [
    "#t-test (significant difference between cogs and sales?)\n",
    "print(\"Avg. Total Sales:  \", salesdf['Total'].mean())\n",
    "print(\"Avg. COGS:  \", salesdf['cogs'].mean())\n",
    "t_val, p_val = ttest_ind(salesdf['Total'], salesdf['cogs'])\n",
    "print(\"(Total Sales, COGS) => t-value=%s, p-value=%s\" % (str(t_val), str(p_val)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Avg. Gross Income:   15.379369000000002\n",
      "Avg. COGS:   307.58738000000034\n",
      "(Gross Income, COGS) => t-value=-39.41001488351556, p-value=8.076365423450553e-252\n"
     ]
    }
   ],
   "source": [
    "#t-test (significant difference between cogs and income?)\n",
    "print(\"Avg. Gross Income:  \", salesdf['gross income'].mean())\n",
    "print(\"Avg. COGS:  \", salesdf['cogs'].mean())\n",
    "t_val, p_val = ttest_ind(salesdf['gross income'], salesdf['cogs'])\n",
    "print(\"(Gross Income, COGS) => t-value=%s, p-value=%s\" % (str(t_val), str(p_val)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Income - Branch\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Branch\"))</th>\n",
       "      <td>242.602644</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.884583</td>\n",
       "      <td>0.41321</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>136716.894906</td>\n",
       "      <td>997.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       sum_sq     df         F   PR(>F)\n",
       "C(Q(\"Branch\"))     242.602644    2.0  0.884583  0.41321\n",
       "Residual        136716.894906  997.0       NaN      NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Income - Customer Type\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Customer type\"))</th>\n",
       "      <td>52.992373</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.386296</td>\n",
       "      <td>0.534395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>136906.505178</td>\n",
       "      <td>998.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Customer type\"))      52.992373    1.0  0.386296  0.534395\n",
       "Residual               136906.505178  998.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Income - Gender\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Gender\"))</th>\n",
       "      <td>334.920796</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.446492</td>\n",
       "      <td>0.118105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>136624.576754</td>\n",
       "      <td>998.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Gender\"))     334.920796    1.0  2.446492  0.118105\n",
       "Residual        136624.576754  998.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Income - Product Line\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Product line\"))</th>\n",
       "      <td>232.439269</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.337965</td>\n",
       "      <td>0.89004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>136727.058281</td>\n",
       "      <td>994.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             sum_sq     df         F   PR(>F)\n",
       "C(Q(\"Product line\"))     232.439269    5.0  0.337965  0.89004\n",
       "Residual              136727.058281  994.0       NaN      NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Income - Payment\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Payment\"))</th>\n",
       "      <td>22.279177</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.081104</td>\n",
       "      <td>0.922104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>136937.218373</td>\n",
       "      <td>997.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Payment\"))      22.279177    2.0  0.081104  0.922104\n",
       "Residual         136937.218373  997.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#anova\n",
    "GI = salesdf['gross income']\n",
    "model = ols('GI ~ C(Q(\"Branch\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Income - Branch\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('GI ~ C(Q(\"Customer type\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Income - Customer Type\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('GI ~ C(Q(\"Gender\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Income - Gender\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('GI ~ C(Q(\"Product line\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Income - Product Line\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('GI ~ C(Q(\"Payment\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Income - Payment\")\n",
    "display(anova_table)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Avg. Income is not varying across any of these groups"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Sales - Branch\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Branch\"))</th>\n",
       "      <td>1.069878e+05</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.884583</td>\n",
       "      <td>0.41321</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>6.029215e+07</td>\n",
       "      <td>997.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      sum_sq     df         F   PR(>F)\n",
       "C(Q(\"Branch\"))  1.069878e+05    2.0  0.884583  0.41321\n",
       "Residual        6.029215e+07  997.0       NaN      NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Sales - Customer Type\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Customer type\"))</th>\n",
       "      <td>2.336964e+04</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.386296</td>\n",
       "      <td>0.534395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>6.037577e+07</td>\n",
       "      <td>998.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Customer type\"))  2.336964e+04    1.0  0.386296  0.534395\n",
       "Residual               6.037577e+07  998.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Sales - Gender\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Gender\"))</th>\n",
       "      <td>1.477001e+05</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.446492</td>\n",
       "      <td>0.118105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>6.025144e+07</td>\n",
       "      <td>998.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Gender\"))  1.477001e+05    1.0  2.446492  0.118105\n",
       "Residual        6.025144e+07  998.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Sales - Product Line\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Product line\"))</th>\n",
       "      <td>1.025057e+05</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.337965</td>\n",
       "      <td>0.89004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>6.029663e+07</td>\n",
       "      <td>994.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            sum_sq     df         F   PR(>F)\n",
       "C(Q(\"Product line\"))  1.025057e+05    5.0  0.337965  0.89004\n",
       "Residual              6.029663e+07  994.0       NaN      NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Sales - Payment\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Payment\"))</th>\n",
       "      <td>9.825117e+03</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.081104</td>\n",
       "      <td>0.922104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>6.038931e+07</td>\n",
       "      <td>997.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Payment\"))  9.825117e+03    2.0  0.081104  0.922104\n",
       "Residual         6.038931e+07  997.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#anova\n",
    "model = ols('Total ~ C(Q(\"Branch\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Sales - Branch\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Total ~ C(Q(\"Customer type\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Sales - Customer Type\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Total ~ C(Q(\"Gender\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Sales - Gender\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Total ~ C(Q(\"Product line\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Sales - Product Line\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Total ~ C(Q(\"Payment\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Sales - Payment\")\n",
    "display(anova_table)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Avg. Sales is also not varying across any of these groups"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Rating - Branch\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Branch\"))</th>\n",
       "      <td>12.233579</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.075477</td>\n",
       "      <td>0.126038</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>2938.331131</td>\n",
       "      <td>997.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Branch\"))    12.233579    2.0  2.075477  0.126038\n",
       "Residual        2938.331131  997.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Rating - Customer Type\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Customer type\"))</th>\n",
       "      <td>1.052708</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.356195</td>\n",
       "      <td>0.550762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>2949.512002</td>\n",
       "      <td>998.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Customer type\"))     1.052708    1.0  0.356195  0.550762\n",
       "Residual               2949.512002  998.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Rating - Gender\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Gender\"))</th>\n",
       "      <td>0.067987</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.022996</td>\n",
       "      <td>0.879497</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>2950.496723</td>\n",
       "      <td>998.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Gender\"))     0.067987    1.0  0.022996  0.879497\n",
       "Residual        2950.496723  998.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Rating - Product Line\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Product line\"))</th>\n",
       "      <td>7.991348</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.539895</td>\n",
       "      <td>0.746137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>2942.573362</td>\n",
       "      <td>994.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Product line\"))     7.991348    5.0  0.539895  0.746137\n",
       "Residual              2942.573362  994.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Rating - Payment\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Payment\"))</th>\n",
       "      <td>0.505457</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.085412</td>\n",
       "      <td>0.918141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>2950.059253</td>\n",
       "      <td>997.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Payment\"))     0.505457    2.0  0.085412  0.918141\n",
       "Residual         2950.059253  997.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#anova\n",
    "model = ols('Rating ~ C(Q(\"Branch\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Rating - Branch\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Rating ~ C(Q(\"Customer type\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Rating - Customer Type\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Rating ~ C(Q(\"Gender\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Rating - Gender\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Rating ~ C(Q(\"Product line\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Rating - Product Line\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Rating ~ C(Q(\"Payment\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Rating - Payment\")\n",
    "display(anova_table)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Avg. Rating also not varying across any of these groups"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => cogs - Branch\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Branch\"))</th>\n",
       "      <td>9.704106e+04</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.884583</td>\n",
       "      <td>0.41321</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>5.468676e+07</td>\n",
       "      <td>997.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      sum_sq     df         F   PR(>F)\n",
       "C(Q(\"Branch\"))  9.704106e+04    2.0  0.884583  0.41321\n",
       "Residual        5.468676e+07  997.0       NaN      NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => cogs - Customer Type\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Customer type\"))</th>\n",
       "      <td>2.119695e+04</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.386296</td>\n",
       "      <td>0.534395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>5.476260e+07</td>\n",
       "      <td>998.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Customer type\"))  2.119695e+04    1.0  0.386296  0.534395\n",
       "Residual               5.476260e+07  998.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => cogs - Gender\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Gender\"))</th>\n",
       "      <td>1.339683e+05</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.446492</td>\n",
       "      <td>0.118105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>5.464983e+07</td>\n",
       "      <td>998.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Gender\"))  1.339683e+05    1.0  2.446492  0.118105\n",
       "Residual        5.464983e+07  998.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => cogs - Product Line\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Product line\"))</th>\n",
       "      <td>9.297571e+04</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.337965</td>\n",
       "      <td>0.89004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>5.469082e+07</td>\n",
       "      <td>994.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            sum_sq     df         F   PR(>F)\n",
       "C(Q(\"Product line\"))  9.297571e+04    5.0  0.337965  0.89004\n",
       "Residual              5.469082e+07  994.0       NaN      NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => cogs - Payment\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Payment\"))</th>\n",
       "      <td>8.911671e+03</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.081104</td>\n",
       "      <td>0.922104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>5.477489e+07</td>\n",
       "      <td>997.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Payment\"))  8.911671e+03    2.0  0.081104  0.922104\n",
       "Residual         5.477489e+07  997.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#anova\n",
    "model = ols('cogs ~ C(Q(\"Branch\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => cogs - Branch\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('cogs ~ C(Q(\"Customer type\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => cogs - Customer Type\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('cogs ~ C(Q(\"Gender\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => cogs - Gender\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('cogs ~ C(Q(\"Product line\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => cogs - Product Line\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('cogs ~ C(Q(\"Payment\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => cogs - Payment\")\n",
    "display(anova_table)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Avg. Rating also not varying across any of these groups"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Quantity - Branch\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Branch\"))</th>\n",
       "      <td>2.586877</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.151085</td>\n",
       "      <td>0.859794</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>8535.313123</td>\n",
       "      <td>997.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Branch\"))     2.586877    2.0  0.151085  0.859794\n",
       "Residual        8535.313123  997.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Quantity - Customer Type\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Customer type\"))</th>\n",
       "      <td>2.39905</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.280505</td>\n",
       "      <td>0.596488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>8535.50095</td>\n",
       "      <td>998.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Customer type\"))     2.39905    1.0  0.280505  0.596488\n",
       "Residual               8535.50095  998.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Quantity - Gender\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Gender\"))</th>\n",
       "      <td>47.080509</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.533782</td>\n",
       "      <td>0.018846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>8490.819491</td>\n",
       "      <td>998.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Gender\"))    47.080509    1.0  5.533782  0.018846\n",
       "Residual        8490.819491  998.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Quantity - Product Line\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Product line\"))</th>\n",
       "      <td>49.409206</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.157161</td>\n",
       "      <td>0.328451</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>8488.490794</td>\n",
       "      <td>994.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Product line\"))    49.409206    5.0  1.157161  0.328451\n",
       "Residual              8488.490794  994.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Anova => Quantity - Payment\n"
     ]
    },
    {
     "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>sum_sq</th>\n",
       "      <th>df</th>\n",
       "      <th>F</th>\n",
       "      <th>PR(&gt;F)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C(Q(\"Payment\"))</th>\n",
       "      <td>0.459434</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.026826</td>\n",
       "      <td>0.973531</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Residual</th>\n",
       "      <td>8537.440566</td>\n",
       "      <td>997.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      sum_sq     df         F    PR(>F)\n",
       "C(Q(\"Payment\"))     0.459434    2.0  0.026826  0.973531\n",
       "Residual         8537.440566  997.0       NaN       NaN"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#anova\n",
    "model = ols('Quantity ~ C(Q(\"Branch\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Quantity - Branch\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Quantity ~ C(Q(\"Customer type\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Quantity - Customer Type\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Quantity ~ C(Q(\"Gender\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Quantity - Gender\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Quantity ~ C(Q(\"Product line\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Quantity - Product Line\")\n",
    "display(anova_table)\n",
    "\n",
    "model = ols('Quantity ~ C(Q(\"Payment\"))', data=salesdf).fit()\n",
    "anova_table = sm.stats.anova_lm(model, typ=2)\n",
    "print (\"\\nAnova => Quantity - Payment\")\n",
    "display(anova_table)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Only the quantity bought seems to be varying and that also wrt gender"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Multiple Comparison of Means - Tukey HSD, FWER=0.05\n",
      "==================================================\n",
      "group1 group2 meandiff p-adj  lower  upper  reject\n",
      "--------------------------------------------------\n",
      "Female   Male   -0.434 0.0188 -0.796 -0.072   True\n",
      "--------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 6852 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "tukey = pairwise_tukeyhsd(endog=salesdf['Quantity'],\n",
    "                          groups=salesdf['Gender'],\n",
    "                          alpha=0.05)\n",
    "\n",
    "#display results\n",
    "print(tukey)\n",
    "\n",
    "salesdf.pivot_table(columns=['Gender'], values='Quantity', aggfunc=np.mean).round(2).plot.bar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Product line  Electronic accessories  Fashion accessories  Food and beverages  \\\n",
      "Branch                                                                          \n",
      "A                                 60                   51                  58   \n",
      "B                                 55                   62                  50   \n",
      "C                                 55                   65                  66   \n",
      "\n",
      "Product line  Health and beauty  Home and lifestyle  Sports and travel  \n",
      "Branch                                                                  \n",
      "A                            47                  65                 59  \n",
      "B                            53                  50                 62  \n",
      "C                            52                  45                 45  \n",
      "dof=10\n",
      "[[57.8   60.52  59.16  51.68  54.4   56.44 ]\n",
      " [56.44  59.096 57.768 50.464 53.12  55.112]\n",
      " [55.76  58.384 57.072 49.856 52.48  54.448]]\n",
      "significance=0.050, p=0.316\n",
      "Independent (fail to reject H0)\n"
     ]
    }
   ],
   "source": [
    "data_crosstab = pd.crosstab(salesdf['Branch'], salesdf['Product line'], \n",
    "margins = False) \n",
    "print(data_crosstab) \n",
    "\n",
    "stat, p, dof, expected = chi2_contingency(data_crosstab)\n",
    "print('dof=%d' % dof)\n",
    "print(expected)\n",
    "\n",
    "# interpret p-value\n",
    "alpha = 0.05\n",
    "print('significance=%.3f, p=%.3f' % (alpha, p))\n",
    "if p <= alpha:\n",
    "    print('Dependent (reject H0)')\n",
    "else:\n",
    "    print('Independent (fail to reject H0)')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Product line  Electronic accessories  Fashion accessories  Food and beverages  \\\n",
      "City                                                                            \n",
      "Mandalay                          55                   62                  50   \n",
      "Naypyitaw                         55                   65                  66   \n",
      "Yangon                            60                   51                  58   \n",
      "\n",
      "Product line  Health and beauty  Home and lifestyle  Sports and travel  \n",
      "City                                                                    \n",
      "Mandalay                     53                  50                 62  \n",
      "Naypyitaw                    52                  45                 45  \n",
      "Yangon                       47                  65                 59  \n",
      "dof=10\n",
      "[[56.44  59.096 57.768 50.464 53.12  55.112]\n",
      " [55.76  58.384 57.072 49.856 52.48  54.448]\n",
      " [57.8   60.52  59.16  51.68  54.4   56.44 ]]\n",
      "significance=0.050, p=0.316\n",
      "Independent (fail to reject H0)\n"
     ]
    }
   ],
   "source": [
    "data_crosstab = pd.crosstab(salesdf['City'], salesdf['Product line'], \n",
    "margins = False) \n",
    "print(data_crosstab) \n",
    "\n",
    "stat, p, dof, expected = chi2_contingency(data_crosstab)\n",
    "print('dof=%d' % dof)\n",
    "print(expected)\n",
    "\n",
    "# interpret p-value\n",
    "alpha = 0.05\n",
    "print('significance=%.3f, p=%.3f' % (alpha, p))\n",
    "if p <= alpha:\n",
    "    print('Dependent (reject H0)')\n",
    "else:\n",
    "    print('Independent (fail to reject H0)')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Product line   Electronic accessories  Fashion accessories  \\\n",
      "Customer type                                                \n",
      "Member                             78                   86   \n",
      "Normal                             92                   92   \n",
      "\n",
      "Product line   Food and beverages  Health and beauty  Home and lifestyle  \\\n",
      "Customer type                                                              \n",
      "Member                         94                 73                  83   \n",
      "Normal                         80                 79                  77   \n",
      "\n",
      "Product line   Sports and travel  \n",
      "Customer type                     \n",
      "Member                        87  \n",
      "Normal                        79  \n",
      "dof=5\n",
      "[[85.17  89.178 87.174 76.152 80.16  83.166]\n",
      " [84.83  88.822 86.826 75.848 79.84  82.834]]\n",
      "significance=0.050, p=0.650\n",
      "Independent (fail to reject H0)\n"
     ]
    }
   ],
   "source": [
    "data_crosstab = pd.crosstab(salesdf['Customer type'], salesdf['Product line'], \n",
    "margins = False) \n",
    "print(data_crosstab) \n",
    "\n",
    "stat, p, dof, expected = chi2_contingency(data_crosstab)\n",
    "print('dof=%d' % dof)\n",
    "print(expected)\n",
    "\n",
    "# interpret p-value\n",
    "alpha = 0.05\n",
    "print('significance=%.3f, p=%.3f' % (alpha, p))\n",
    "if p <= alpha:\n",
    "    print('Dependent (reject H0)')\n",
    "else:\n",
    "    print('Independent (fail to reject H0)')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Product line  Electronic accessories  Fashion accessories  Food and beverages  \\\n",
      "Gender                                                                          \n",
      "Female                            84                   96                  90   \n",
      "Male                              86                   82                  84   \n",
      "\n",
      "Product line  Health and beauty  Home and lifestyle  Sports and travel  \n",
      "Gender                                                                  \n",
      "Female                       64                  79                 88  \n",
      "Male                         88                  81                 78  \n",
      "dof=5\n",
      "[[85.17  89.178 87.174 76.152 80.16  83.166]\n",
      " [84.83  88.822 86.826 75.848 79.84  82.834]]\n",
      "significance=0.050, p=0.332\n",
      "Independent (fail to reject H0)\n"
     ]
    }
   ],
   "source": [
    "data_crosstab = pd.crosstab(salesdf['Gender'], salesdf['Product line'], \n",
    "margins = False) \n",
    "print(data_crosstab) \n",
    "\n",
    "stat, p, dof, expected = chi2_contingency(data_crosstab)\n",
    "print('dof=%d' % dof)\n",
    "print(expected)\n",
    "\n",
    "# interpret p-value\n",
    "alpha = 0.05\n",
    "print('significance=%.3f, p=%.3f' % (alpha, p))\n",
    "if p <= alpha:\n",
    "    print('Dependent (reject H0)')\n",
    "else:\n",
    "    print('Independent (fail to reject H0)')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Product line  Electronic accessories  Fashion accessories  Food and beverages  \\\n",
      "Payment                                                                         \n",
      "Cash                              71                   57                  57   \n",
      "Credit card                       46                   56                  61   \n",
      "Ewallet                           53                   65                  56   \n",
      "\n",
      "Product line  Health and beauty  Home and lifestyle  Sports and travel  \n",
      "Payment                                                                 \n",
      "Cash                         49                  51                 59  \n",
      "Credit card                  50                  45                 53  \n",
      "Ewallet                      53                  64                 54  \n",
      "dof=10\n",
      "[[58.48  61.232 59.856 52.288 55.04  57.104]\n",
      " [52.87  55.358 54.114 47.272 49.76  51.626]\n",
      " [58.65  61.41  60.03  52.44  55.2   57.27 ]]\n",
      "significance=0.050, p=0.559\n",
      "Independent (fail to reject H0)\n"
     ]
    }
   ],
   "source": [
    "data_crosstab = pd.crosstab(salesdf['Payment'], salesdf['Product line'], \n",
    "margins = False) \n",
    "print(data_crosstab) \n",
    "\n",
    "stat, p, dof, expected = chi2_contingency(data_crosstab)\n",
    "print('dof=%d' % dof)\n",
    "print(expected)\n",
    "\n",
    "# interpret p-value\n",
    "alpha = 0.05\n",
    "print('significance=%.3f, p=%.3f' % (alpha, p))\n",
    "if p <= alpha:\n",
    "    print('Dependent (reject H0)')\n",
    "else:\n",
    "    print('Independent (fail to reject H0)')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gross Income\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 4520 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "COGS\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 4788 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sales\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 4792 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Quantity\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 4912 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "print (\"Gross Income\")\n",
    "pyplot.hist(salesdf['gross income'])\n",
    "pyplot.show()\n",
    "\n",
    "print (\"COGS\")\n",
    "pyplot.hist(salesdf['cogs'])\n",
    "pyplot.show()\n",
    "\n",
    "print (\"Sales\")\n",
    "pyplot.hist(salesdf['Total'])\n",
    "pyplot.show()\n",
    "\n",
    "print (\"Quantity\")\n",
    "pyplot.hist(salesdf['Quantity'])\n",
    "pyplot.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output: 28.4745\n",
      "15.0000: 0.5740, data not look normal (reject H0)\n",
      "10.0000: 0.6530, data not look normal (reject H0)\n",
      "5.0000: 0.7840, data not look normal (reject H0)\n",
      "2.5000: 0.9140, data not look normal (reject H0)\n",
      "1.0000: 1.0880, data not look normal (reject H0)\n"
     ]
    }
   ],
   "source": [
    "output = anderson(salesdf['gross income'])\n",
    "print('Output: %.4f' % output.statistic)\n",
    "\n",
    "p = 0\n",
    "for i in range(len(output.critical_values)):\n",
    "    sl, cv = output.significance_level[i], output.critical_values[i]\n",
    "    if output.statistic < output.critical_values[i]:\n",
    "        print('%.4f: %.4f, data looks normal (cant reject H0)' % (sl, cv))\n",
    "    else:\n",
    "        print('%.4f: %.4f, data not look normal (reject H0)' % (sl, cv))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output: 28.4745\n",
      "15.0000: 0.5740, data not look normal (reject H0)\n",
      "10.0000: 0.6530, data not look normal (reject H0)\n",
      "5.0000: 0.7840, data not look normal (reject H0)\n",
      "2.5000: 0.9140, data not look normal (reject H0)\n",
      "1.0000: 1.0880, data not look normal (reject H0)\n"
     ]
    }
   ],
   "source": [
    "output = anderson(salesdf['Total'])\n",
    "print('Output: %.4f' % output.statistic)\n",
    "\n",
    "p = 0\n",
    "for i in range(len(output.critical_values)):\n",
    "    sl, cv = output.significance_level[i], output.critical_values[i]\n",
    "    if output.statistic < output.critical_values[i]:\n",
    "        print('%.4f: %.4f, data looks normal (cant reject H0)' % (sl, cv))\n",
    "    else:\n",
    "        print('%.4f: %.4f, data not look normal (reject H0)' % (sl, cv))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 16204 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "qqplot(salesdf['gross income'], line='s')\n",
    "pyplot.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 17232 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "qqplot(salesdf['Total'], line='s')\n",
    "pyplot.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
