{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import scipy.stats as stats\n",
    "\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "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>Emp #</th>\n",
       "      <th>Designation</th>\n",
       "      <th>Experience</th>\n",
       "      <th>Salary</th>\n",
       "      <th>AggrBehavScore</th>\n",
       "      <th>ActivityScore</th>\n",
       "      <th>LinesOfCode</th>\n",
       "      <th>Qualification</th>\n",
       "      <th>Degree</th>\n",
       "      <th>YearsOfStudy</th>\n",
       "      <th>EducationalInstitute</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Empl_Band</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>e1</td>\n",
       "      <td>Director</td>\n",
       "      <td>15.0</td>\n",
       "      <td>85000</td>\n",
       "      <td>0.33</td>\n",
       "      <td>2</td>\n",
       "      <td>1332</td>\n",
       "      <td>Grad</td>\n",
       "      <td>NaN</td>\n",
       "      <td>15.0</td>\n",
       "      <td>clg</td>\n",
       "      <td>M</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>e2</td>\n",
       "      <td>Jr.Dev</td>\n",
       "      <td>3.0</td>\n",
       "      <td>25000</td>\n",
       "      <td>5.67</td>\n",
       "      <td>16</td>\n",
       "      <td>6666</td>\n",
       "      <td>Grad</td>\n",
       "      <td>Btech</td>\n",
       "      <td>16.0</td>\n",
       "      <td>clg</td>\n",
       "      <td>F</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>e3</td>\n",
       "      <td>Sr.Dev</td>\n",
       "      <td>6.0</td>\n",
       "      <td>36000</td>\n",
       "      <td>2.33</td>\n",
       "      <td>7</td>\n",
       "      <td>3332</td>\n",
       "      <td>PostGrad</td>\n",
       "      <td>Msc</td>\n",
       "      <td>17.0</td>\n",
       "      <td>unv</td>\n",
       "      <td>M</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>e4</td>\n",
       "      <td>Jr.Dev</td>\n",
       "      <td>2.0</td>\n",
       "      <td>20000</td>\n",
       "      <td>9.00</td>\n",
       "      <td>24</td>\n",
       "      <td>9999</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Mtech</td>\n",
       "      <td>18.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>F</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>e5</td>\n",
       "      <td>Sr.Dev</td>\n",
       "      <td>5.0</td>\n",
       "      <td>37000</td>\n",
       "      <td>3.00</td>\n",
       "      <td>9</td>\n",
       "      <td>3999</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Btech</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>F</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>e6</td>\n",
       "      <td>Sr.Dev</td>\n",
       "      <td>6.5</td>\n",
       "      <td>36300</td>\n",
       "      <td>2.08</td>\n",
       "      <td>7</td>\n",
       "      <td>3076</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>15.0</td>\n",
       "      <td>unv</td>\n",
       "      <td>M</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>e7</td>\n",
       "      <td>Sr.Dev</td>\n",
       "      <td>5.3</td>\n",
       "      <td>32000</td>\n",
       "      <td>2.77</td>\n",
       "      <td>8</td>\n",
       "      <td>3773</td>\n",
       "      <td>PostGrad</td>\n",
       "      <td>IntMsc</td>\n",
       "      <td>NaN</td>\n",
       "      <td>cunv</td>\n",
       "      <td>F</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>e8</td>\n",
       "      <td>Director</td>\n",
       "      <td>17.0</td>\n",
       "      <td>89500</td>\n",
       "      <td>0.18</td>\n",
       "      <td>2</td>\n",
       "      <td>1175</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>e9</td>\n",
       "      <td>Manager</td>\n",
       "      <td>10.0</td>\n",
       "      <td>63265</td>\n",
       "      <td>1.00</td>\n",
       "      <td>4</td>\n",
       "      <td>1999</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>18.0</td>\n",
       "      <td>iit</td>\n",
       "      <td>F</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>e10</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "      <td>9.5</td>\n",
       "      <td>50500</td>\n",
       "      <td>1.11</td>\n",
       "      <td>4</td>\n",
       "      <td>2104</td>\n",
       "      <td>Grad</td>\n",
       "      <td>B.A</td>\n",
       "      <td>15.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>e11</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "      <td>9.5</td>\n",
       "      <td>53476</td>\n",
       "      <td>1.11</td>\n",
       "      <td>4</td>\n",
       "      <td>2104</td>\n",
       "      <td>Phd</td>\n",
       "      <td>NaN</td>\n",
       "      <td>22.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>e12</td>\n",
       "      <td>Sr.Manager</td>\n",
       "      <td>12.0</td>\n",
       "      <td>73240</td>\n",
       "      <td>0.67</td>\n",
       "      <td>3</td>\n",
       "      <td>1666</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Msc</td>\n",
       "      <td>27.0</td>\n",
       "      <td>iit</td>\n",
       "      <td>F</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>e13</td>\n",
       "      <td>Analyst</td>\n",
       "      <td>8.0</td>\n",
       "      <td>44900</td>\n",
       "      <td>1.50</td>\n",
       "      <td>5</td>\n",
       "      <td>2499</td>\n",
       "      <td>PostGrad</td>\n",
       "      <td>Mba</td>\n",
       "      <td>19.0</td>\n",
       "      <td>clg</td>\n",
       "      <td>M</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>e14</td>\n",
       "      <td>Analyst</td>\n",
       "      <td>8.3</td>\n",
       "      <td>42600</td>\n",
       "      <td>1.41</td>\n",
       "      <td>5</td>\n",
       "      <td>2409</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>F</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>e15</td>\n",
       "      <td>Analyst</td>\n",
       "      <td>8.1</td>\n",
       "      <td>46000</td>\n",
       "      <td>1.47</td>\n",
       "      <td>5</td>\n",
       "      <td>2468</td>\n",
       "      <td>Grad</td>\n",
       "      <td>Bsc</td>\n",
       "      <td>15.0</td>\n",
       "      <td>iit</td>\n",
       "      <td>F</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>e16</td>\n",
       "      <td>Manager</td>\n",
       "      <td>10.2</td>\n",
       "      <td>65000</td>\n",
       "      <td>0.96</td>\n",
       "      <td>4</td>\n",
       "      <td>1960</td>\n",
       "      <td>Grad</td>\n",
       "      <td>Btech</td>\n",
       "      <td>16.0</td>\n",
       "      <td>clg</td>\n",
       "      <td>M</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>e17</td>\n",
       "      <td>Manager</td>\n",
       "      <td>9.8</td>\n",
       "      <td>67200</td>\n",
       "      <td>1.04</td>\n",
       "      <td>4</td>\n",
       "      <td>2040</td>\n",
       "      <td>Grad</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>e18</td>\n",
       "      <td>Sr.Manager</td>\n",
       "      <td>13.0</td>\n",
       "      <td>78200</td>\n",
       "      <td>0.54</td>\n",
       "      <td>3</td>\n",
       "      <td>1537</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>15.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>e19</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "      <td>7.5</td>\n",
       "      <td>52890</td>\n",
       "      <td>1.67</td>\n",
       "      <td>6</td>\n",
       "      <td>2666</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>e20</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "      <td>8.7</td>\n",
       "      <td>57000</td>\n",
       "      <td>1.30</td>\n",
       "      <td>5</td>\n",
       "      <td>2298</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>F</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>e21</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "      <td>8.1</td>\n",
       "      <td>58200</td>\n",
       "      <td>1.47</td>\n",
       "      <td>5</td>\n",
       "      <td>2468</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>e22</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "      <td>8.0</td>\n",
       "      <td>50500</td>\n",
       "      <td>1.50</td>\n",
       "      <td>5</td>\n",
       "      <td>2499</td>\n",
       "      <td>postdoc</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>F</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>e23</td>\n",
       "      <td>Analyst</td>\n",
       "      <td>7.2</td>\n",
       "      <td>42300</td>\n",
       "      <td>1.78</td>\n",
       "      <td>6</td>\n",
       "      <td>2777</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>15.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>e24</td>\n",
       "      <td>Analyst</td>\n",
       "      <td>7.5</td>\n",
       "      <td>47800</td>\n",
       "      <td>1.67</td>\n",
       "      <td>6</td>\n",
       "      <td>2666</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>15.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>e25</td>\n",
       "      <td>Analyst</td>\n",
       "      <td>7.7</td>\n",
       "      <td>41000</td>\n",
       "      <td>1.60</td>\n",
       "      <td>5</td>\n",
       "      <td>2596</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>15.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>e26</td>\n",
       "      <td>Manager</td>\n",
       "      <td>10.0</td>\n",
       "      <td>63333</td>\n",
       "      <td>1.00</td>\n",
       "      <td>4</td>\n",
       "      <td>1999</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>17.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>e27</td>\n",
       "      <td>Manager</td>\n",
       "      <td>11.2</td>\n",
       "      <td>67343</td>\n",
       "      <td>0.79</td>\n",
       "      <td>3</td>\n",
       "      <td>1785</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>17.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>e28</td>\n",
       "      <td>Manager</td>\n",
       "      <td>10.5</td>\n",
       "      <td>69000</td>\n",
       "      <td>0.90</td>\n",
       "      <td>4</td>\n",
       "      <td>1904</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>F</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>e29</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "      <td>12.0</td>\n",
       "      <td>79000</td>\n",
       "      <td>0.67</td>\n",
       "      <td>3</td>\n",
       "      <td>1666</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>17.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>F</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>e30</td>\n",
       "      <td>Sr.Manager</td>\n",
       "      <td>13.2</td>\n",
       "      <td>72998</td>\n",
       "      <td>0.52</td>\n",
       "      <td>3</td>\n",
       "      <td>1514</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>19.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>F</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>e31</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "      <td>10.2</td>\n",
       "      <td>51000</td>\n",
       "      <td>0.96</td>\n",
       "      <td>4</td>\n",
       "      <td>1960</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>M</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>e32</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "      <td>9.9</td>\n",
       "      <td>54000</td>\n",
       "      <td>1.02</td>\n",
       "      <td>4</td>\n",
       "      <td>2019</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>35.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>F</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Emp # Designation  Experience  Salary  AggrBehavScore  ActivityScore  \\\n",
       "0     e1    Director        15.0   85000            0.33              2   \n",
       "1     e2      Jr.Dev         3.0   25000            5.67             16   \n",
       "2     e3      Sr.Dev         6.0   36000            2.33              7   \n",
       "3     e4      Jr.Dev         2.0   20000            9.00             24   \n",
       "4     e5      Sr.Dev         5.0   37000            3.00              9   \n",
       "5     e6      Sr.Dev         6.5   36300            2.08              7   \n",
       "6     e7      Sr.Dev         5.3   32000            2.77              8   \n",
       "7     e8    Director        17.0   89500            0.18              2   \n",
       "8     e9     Manager        10.0   63265            1.00              4   \n",
       "9    e10  Sr.Analyst         9.5   50500            1.11              4   \n",
       "10   e11  Sr.Analyst         9.5   53476            1.11              4   \n",
       "11   e12  Sr.Manager        12.0   73240            0.67              3   \n",
       "12   e13     Analyst         8.0   44900            1.50              5   \n",
       "13   e14     Analyst         8.3   42600            1.41              5   \n",
       "14   e15     Analyst         8.1   46000            1.47              5   \n",
       "15   e16     Manager        10.2   65000            0.96              4   \n",
       "16   e17     Manager         9.8   67200            1.04              4   \n",
       "17   e18  Sr.Manager        13.0   78200            0.54              3   \n",
       "18   e19  Sr.Analyst         7.5   52890            1.67              6   \n",
       "19   e20  Sr.Analyst         8.7   57000            1.30              5   \n",
       "20   e21  Sr.Analyst         8.1   58200            1.47              5   \n",
       "21   e22  Sr.Analyst         8.0   50500            1.50              5   \n",
       "22   e23     Analyst         7.2   42300            1.78              6   \n",
       "23   e24     Analyst         7.5   47800            1.67              6   \n",
       "24   e25     Analyst         7.7   41000            1.60              5   \n",
       "25   e26     Manager        10.0   63333            1.00              4   \n",
       "26   e27     Manager        11.2   67343            0.79              3   \n",
       "27   e28     Manager        10.5   69000            0.90              4   \n",
       "28   e29  Sr.Analyst        12.0   79000            0.67              3   \n",
       "29   e30  Sr.Manager        13.2   72998            0.52              3   \n",
       "30   e31  Sr.Analyst        10.2   51000            0.96              4   \n",
       "31   e32  Sr.Analyst         9.9   54000            1.02              4   \n",
       "\n",
       "    LinesOfCode Qualification  Degree  YearsOfStudy EducationalInstitute  \\\n",
       "0          1332          Grad     NaN          15.0                  clg   \n",
       "1          6666          Grad   Btech          16.0                  clg   \n",
       "2          3332      PostGrad     Msc          17.0                  unv   \n",
       "3          9999           NaN   Mtech          18.0                  NaN   \n",
       "4          3999           NaN   Btech          16.0                  NaN   \n",
       "5          3076           NaN     NaN          15.0                  unv   \n",
       "6          3773      PostGrad  IntMsc           NaN                 cunv   \n",
       "7          1175           NaN     NaN           NaN                  NaN   \n",
       "8          1999           NaN     NaN          18.0                  iit   \n",
       "9          2104          Grad     B.A          15.0                  NaN   \n",
       "10         2104           Phd     NaN          22.0                  NaN   \n",
       "11         1666           NaN     Msc          27.0                  iit   \n",
       "12         2499      PostGrad     Mba          19.0                  clg   \n",
       "13         2409           NaN     NaN           NaN                  NaN   \n",
       "14         2468          Grad     Bsc          15.0                  iit   \n",
       "15         1960          Grad   Btech          16.0                  clg   \n",
       "16         2040          Grad     NaN           NaN                  NaN   \n",
       "17         1537           NaN     NaN          15.0                  NaN   \n",
       "18         2666           NaN     NaN          16.0                  NaN   \n",
       "19         2298           NaN     NaN           NaN                  NaN   \n",
       "20         2468           NaN     NaN           NaN                  NaN   \n",
       "21         2499       postdoc     NaN           NaN                  NaN   \n",
       "22         2777           NaN     NaN          15.0                  NaN   \n",
       "23         2666           NaN     NaN          15.0                  NaN   \n",
       "24         2596           NaN     NaN          15.0                  NaN   \n",
       "25         1999           NaN     NaN          17.0                  NaN   \n",
       "26         1785           NaN     NaN          17.0                  NaN   \n",
       "27         1904           NaN     NaN           NaN                  NaN   \n",
       "28         1666           NaN     NaN          17.0                  NaN   \n",
       "29         1514           NaN     NaN          19.0                  NaN   \n",
       "30         1960           NaN     NaN          29.0                  NaN   \n",
       "31         2019           NaN     NaN          35.0                  NaN   \n",
       "\n",
       "   Gender Empl_Band  \n",
       "0       M         A  \n",
       "1       F         C  \n",
       "2       M         B  \n",
       "3       F         C  \n",
       "4       F         B  \n",
       "5       M         B  \n",
       "6       F         B  \n",
       "7       M         A  \n",
       "8       F         B  \n",
       "9       M         A  \n",
       "10      M         A  \n",
       "11      F         A  \n",
       "12      M         C  \n",
       "13      F         C  \n",
       "14      F         C  \n",
       "15      M         B  \n",
       "16      M         B  \n",
       "17      M         A  \n",
       "18      M         A  \n",
       "19      F         A  \n",
       "20      M         A  \n",
       "21      F         A  \n",
       "22      M         C  \n",
       "23      M         C  \n",
       "24      M         C  \n",
       "25      M         B  \n",
       "26      M         B  \n",
       "27      F         B  \n",
       "28      F         A  \n",
       "29      F         A  \n",
       "30      M         A  \n",
       "31      F         A  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "employee_data=pd.read_csv('employee_data.csv')\n",
    "employee_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Analyze two categorical columns \"Gender\" as input and \"Designation\" as output feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "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>Gender</th>\n",
       "      <th>Designation</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>M</td>\n",
       "      <td>Director</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>F</td>\n",
       "      <td>Jr.Dev</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>M</td>\n",
       "      <td>Sr.Dev</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>F</td>\n",
       "      <td>Jr.Dev</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>F</td>\n",
       "      <td>Sr.Dev</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>M</td>\n",
       "      <td>Sr.Dev</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>F</td>\n",
       "      <td>Sr.Dev</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>M</td>\n",
       "      <td>Director</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>F</td>\n",
       "      <td>Manager</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>M</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>M</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>F</td>\n",
       "      <td>Sr.Manager</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>M</td>\n",
       "      <td>Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>F</td>\n",
       "      <td>Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>F</td>\n",
       "      <td>Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>M</td>\n",
       "      <td>Manager</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>M</td>\n",
       "      <td>Manager</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>M</td>\n",
       "      <td>Sr.Manager</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>M</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>F</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>M</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>F</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>M</td>\n",
       "      <td>Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>M</td>\n",
       "      <td>Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>M</td>\n",
       "      <td>Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>M</td>\n",
       "      <td>Manager</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>M</td>\n",
       "      <td>Manager</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>F</td>\n",
       "      <td>Manager</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>F</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>F</td>\n",
       "      <td>Sr.Manager</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>M</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>F</td>\n",
       "      <td>Sr.Analyst</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Gender Designation\n",
       "0       M    Director\n",
       "1       F      Jr.Dev\n",
       "2       M      Sr.Dev\n",
       "3       F      Jr.Dev\n",
       "4       F      Sr.Dev\n",
       "5       M      Sr.Dev\n",
       "6       F      Sr.Dev\n",
       "7       M    Director\n",
       "8       F     Manager\n",
       "9       M  Sr.Analyst\n",
       "10      M  Sr.Analyst\n",
       "11      F  Sr.Manager\n",
       "12      M     Analyst\n",
       "13      F     Analyst\n",
       "14      F     Analyst\n",
       "15      M     Manager\n",
       "16      M     Manager\n",
       "17      M  Sr.Manager\n",
       "18      M  Sr.Analyst\n",
       "19      F  Sr.Analyst\n",
       "20      M  Sr.Analyst\n",
       "21      F  Sr.Analyst\n",
       "22      M     Analyst\n",
       "23      M     Analyst\n",
       "24      M     Analyst\n",
       "25      M     Manager\n",
       "26      M     Manager\n",
       "27      F     Manager\n",
       "28      F  Sr.Analyst\n",
       "29      F  Sr.Manager\n",
       "30      M  Sr.Analyst\n",
       "31      F  Sr.Analyst"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "employee_data_chi_square = employee_data.loc[:, ['Gender','Designation']]\n",
    "employee_data_chi_square"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['M', 'F'], dtype=object)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "employee_data_chi_square['Gender'].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Director', 'Jr.Dev', 'Sr.Dev', 'Manager', 'Sr.Analyst',\n",
       "       'Sr.Manager', 'Analyst'], dtype=object)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "employee_data_chi_square['Designation'].unique()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1><center><u>Visualization</u></center></h1>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Need to draw a bar graph between \"Gender\" and \"Designation\", first we need to answer below questions to do so.\n",
    "* Q1) What is the type of explanatory variable (Categorical/Quantitative) ?\n",
    "  * **Ans:** \"Gender\" is a Categorical variable\n",
    "  \n",
    "\n",
    "* Q2) What is the type of the response variable (Categorical/Quantitative) ?\n",
    "  * **Ans:** \"Designation\" is a Categorical variable\n",
    "  \n",
    "  \n",
    "* Q3) If response variable is Categorical - find out how many categories are in it ?. \n",
    "  * **<font color='red'>Note:</font>** <u>\"Only Two Categories Should Be Present in Response Variable\"</u> to generate a BAR graph - the response variable must be **collapsed to bi-variate**. \n",
    "  * **Ans:** As we are trying to understand the percentage of \"Managers and above designations (1)\" vs \"below Manager designations (0)\" "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gender column - datatype :  object\n",
      "Designation column - datatype :  object\n",
      "Number of categories in Designation column :  (7,)\n"
     ]
    }
   ],
   "source": [
    "print(\"Gender column - datatype : \", employee_data_chi_square['Gender'].dtype)\n",
    "print(\"Designation column - datatype : \", employee_data_chi_square['Designation'].dtype)\n",
    "\n",
    "print(\"Number of categories in Designation column : \", employee_data_chi_square['Designation'].unique().shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Collapsed \"Designation\" to 2 categories (0, 1) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def mapDesignationToBinary(designation):\n",
    "    if(designation in ['Director', 'Manager', 'Sr.Analyst', 'Sr.Manager']):\n",
    "        return 1\n",
    "    else:\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "employee_data_chi_square[\"Designation_binary\"] = \\\n",
    "                employee_data_chi_square[\"Designation\"].apply(lambda x: mapDesignationToBinary(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1    20\n",
       "0    12\n",
       "Name: Designation_binary, dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "employee_data_chi_square[\"Designation_binary\"].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Bar height shows the percentage of 1's in each category(M/F), it seems women in manageral roles are less compared to men."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(9.444444444444445, 0.5, 'Percentage of Managers')"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 17080 characters]\n",
      "text/plain": [
       "<Figure size 500x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.catplot(data=employee_data_chi_square, \n",
    "            x=\"Gender\", y=\"Designation_binary\", \n",
    "            kind=\"bar\", ci=None)\n",
    "plt.xlabel(\"Genger\")\n",
    "plt.ylabel(\"Percentage of Managers\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Non-Manager percentages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def mapDesignationToBinary(designation):\n",
    "    if(designation in ['Jr.Dev', 'Sr.Dev', 'Analyst']):\n",
    "        return 1\n",
    "    else:\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "employee_data_chi_square[\"Designation_binary\"] = \\\n",
    "                employee_data_chi_square[\"Designation\"].apply(lambda x: mapDesignationToBinary(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    20\n",
       "1    12\n",
       "Name: Designation_binary, dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "employee_data_chi_square[\"Designation_binary\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5694444444444446, 0.5, 'Percentage of Managers')"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 20864 characters]\n",
      "text/plain": [
       "<Figure size 500x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.catplot(data=employee_data_chi_square, x=\"Gender\", y=\"Designation_binary\", kind=\"bar\", ci=None)\n",
    "plt.xlabel(\"Genger\")\n",
    "plt.ylabel(\"Percentage of Managers\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1><center><u>Hypothesis Testing</u></center></h1>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Can we use \"Gender\" to predict \"Designation\" ?. Chi-Square Test for Independence can answer this question as \"Gender\" and \"Designation\" are categorical features."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Hypothesis Testing : Chi-Square Test\n",
    "* **Null Hypothesis (H0):** \"Gender\" of the employee and \"Designation\" are independent\n",
    "* **Alternate Hypothesis (H1):** \"Gender\" of the employee and \"Designation\" are not independent(dependent)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "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>Designation</th>\n",
       "      <th>Analyst</th>\n",
       "      <th>Director</th>\n",
       "      <th>Jr.Dev</th>\n",
       "      <th>Manager</th>\n",
       "      <th>Sr.Analyst</th>\n",
       "      <th>Sr.Dev</th>\n",
       "      <th>Sr.Manager</th>\n",
       "      <th>All</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gender</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>All</th>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>9</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Designation  Analyst  Director  Jr.Dev  Manager  Sr.Analyst  Sr.Dev  \\\n",
       "Gender                                                                \n",
       "F                  2         0       2        2           4       2   \n",
       "M                  4         2       0        4           5       2   \n",
       "All                6         2       2        6           9       4   \n",
       "\n",
       "Designation  Sr.Manager  All  \n",
       "Gender                        \n",
       "F                     2   14  \n",
       "M                     1   18  \n",
       "All                   3   32  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cros_tab_gen_desig = pd.crosstab(employee_data_chi_square.Gender, employee_data_chi_square.Designation, margins = True)\n",
    "cros_tab_gen_desig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "chi2_value, p, dof, ex_table = stats.chi2_contingency(cros_tab_gen_desig, correction=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Expected Values:  [[ 2.625   0.875   0.875   2.625   3.9375  1.75    1.3125 14.    ]\n",
      " [ 3.375   1.125   1.125   3.375   5.0625  2.25    1.6875 18.    ]\n",
      " [ 6.      2.      2.      6.      9.      4.      3.     32.    ]]\n"
     ]
    }
   ],
   "source": [
    "print(\"Expected Values: \", ex_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P - Values:  0.9801175893588029\n"
     ]
    }
   ],
   "source": [
    "print(\"P - Values: \", p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.361552028218695"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chi2_value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* P-Value 0.98 >0.05 (so calculated chi2-value greater than the p-value (level of marginal significance when null hypothesis is true))\n",
    "* We fail to reject null hypothesis so we **accept our null hypothesis H0**\n",
    "* i.e **Gender and designation are independent.**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Chi-Square Test for Independence when Independent Variable has more than 2 Categories"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Hypothesis Testing : Chi-Square Test\n",
    "* **Null Hypothesis (H0):** \"Empl_Band\" of the employee and \"Designation\" are independent\n",
    "* **Alternate Hypothesis (H1):** \"Empl_Band\" of the employee and \"Designation\" are not independent(dependent)."
   ]
  }
 ],
 "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.9.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
