{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "dd53ccfc-98dc-4289-9176-34362b67d8e2",
   "metadata": {},
   "source": [
    "## Introduction to Data Science\n",
    "\n",
    "#### University of Redlands - DATA 101\n",
    "#### Prof: Joanna Bieri [joanna_bieri@redlands.edu](mailto:joanna_bieri@redlands.edu)\n",
    "#### [Class Website: data101.joannabieri.com](https://data101.joannabieri.com)\n",
    "\n",
    "---------------------------------------\n",
    "# Homework Day 11\n",
    "---------------------------------------\n",
    "\n",
    "GOALS:\n",
    "\n",
    "1. Understand Causal vs Experimental Studies\n",
    "2. Do a more free form data analysis\n",
    "3. Start doing your ethics reading\n",
    "\n",
    "----------------------------------------------------------\n",
    "\n",
    "This homework has **2 questions** and **10 exercises**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d0153569-41e3-4696-9b34-83ba90a0b5cf",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-07T17:29:05.543688Z",
     "iopub.status.busy": "2026-10-07T17:29:05.543613Z",
     "iopub.status.idle": "2026-10-07T17:29:06.322970Z",
     "shell.execute_reply": "2026-10-07T17:29:06.322649Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import plotly.express as px\n",
    "from plotly.subplots import make_subplots\n",
    "import plotly.io as pio\n",
    "pio.renderers.default = 'notebook_connected'\n",
    "\n",
    "# This stops a few warning messages from showing\n",
    "pd.options.mode.chained_assignment = None \n",
    "import warnings\n",
    "warnings.simplefilter(action='ignore', category=FutureWarning)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7048dfd1-2b03-4c4b-93e2-ff48f66af288",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-07T17:29:06.325203Z",
     "iopub.status.busy": "2026-10-07T17:29:06.325130Z",
     "iopub.status.idle": "2026-10-07T17:29:06.514004Z",
     "shell.execute_reply": "2026-10-07T17:29:06.513420Z"
    }
   },
   "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>The climate is changing and human activity is mainly responsible</th>\n",
       "      <th>The climate is changing and human activity is partly responsible, together with other factors</th>\n",
       "      <th>The climate is changing but human activity is not responsible at all</th>\n",
       "      <th>The climate is not changing</th>\n",
       "      <th>Don't know</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>country</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>GB</th>\n",
       "      <td>833</td>\n",
       "      <td>604</td>\n",
       "      <td>49</td>\n",
       "      <td>33</td>\n",
       "      <td>114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>US</th>\n",
       "      <td>507</td>\n",
       "      <td>493</td>\n",
       "      <td>120</td>\n",
       "      <td>80</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         The climate is changing and human activity is mainly responsible    \\\n",
       "country                                                                       \n",
       "GB                                                     833                    \n",
       "US                                                     507                    \n",
       "\n",
       "         The climate is changing and human activity is partly responsible, together with other factors    \\\n",
       "country                                                                                                    \n",
       "GB                                                     604                                                 \n",
       "US                                                     493                                                 \n",
       "\n",
       "         The climate is changing but human activity is not responsible at all    \\\n",
       "country                                                                           \n",
       "GB                                                      49                        \n",
       "US                                                     120                        \n",
       "\n",
       "         The climate is not changing    Don't know  \n",
       "country                                             \n",
       "GB                                  33         114  \n",
       "US                                  80         133  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file_name = 'https://joannabieri.com/introdatascience/data/yougov-climate.csv'\n",
    "DF = pd.read_csv(file_name,index_col=0)\n",
    "DF"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed9f27ed-eb76-470c-8f3d-cbc80e2b8ee9",
   "metadata": {},
   "source": [
    "In the lecture we analyzed the following questions for the first column in the data:\n",
    "\n",
    "### First question:\n",
    "\n",
    "What percent of **all respondents** think the climate is changing and human activity is mainly responsible?  \n",
    "\n",
    "### Second question:\n",
    "\n",
    "What percent of **GB respondents** think the climate is changing and  human activity is mainly responsible?  \n",
    "\n",
    "### Third Question\n",
    "\n",
    "What percent of **US respondents** think the climate is changing and  human activity is mainly responsible?  \n",
    "\n",
    "**Q1** Repeat the analysis from the lecture notes for one of the other columns/questions.\n",
    "\n",
    "1. Percent total\n",
    "2. Percent from GB\n",
    "3. Percent from US\n",
    "\n",
    "Talk about the conditional probability in this case:\n",
    "\n",
    "eg. If a person is from ________ then there is a ________ probability that they believe _______. If a person answered _______ then they are more likely to be from ________. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b5874385-5dff-4fbb-ae93-aa8bd386478c",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "249af7fa-4af0-4948-aa1c-6ac55a12b77d",
   "metadata": {},
   "source": [
    "## Berkeley admission data example\n",
    "\n",
    "- Study carried out by the Graduate Division of the University of California, Berkeley in the early 70’s to evaluate whether there was a gender bias in graduate admissions.\n",
    "- The data come from six departments. For confidentiality we'll call them A-F. \n",
    "- We have information on whether the applicant was male or female and whether they were admitted or rejected. This is an old study so only two binary classifications were used. \n",
    "\n",
    "### Here is the data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "18c756ff-0c11-409c-b377-7f271627f33b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-07T17:29:06.516881Z",
     "iopub.status.busy": "2026-10-07T17:29:06.516821Z",
     "iopub.status.idle": "2026-10-07T17:29:06.697095Z",
     "shell.execute_reply": "2026-10-07T17:29:06.696387Z"
    }
   },
   "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>Department</th>\n",
       "      <th>Male Yes</th>\n",
       "      <th>Male No</th>\n",
       "      <th>Female Yes</th>\n",
       "      <th>Female No</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>512</td>\n",
       "      <td>313</td>\n",
       "      <td>89</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B</td>\n",
       "      <td>353</td>\n",
       "      <td>207</td>\n",
       "      <td>17</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C</td>\n",
       "      <td>120</td>\n",
       "      <td>205</td>\n",
       "      <td>202</td>\n",
       "      <td>391</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>D</td>\n",
       "      <td>138</td>\n",
       "      <td>279</td>\n",
       "      <td>131</td>\n",
       "      <td>244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>E</td>\n",
       "      <td>53</td>\n",
       "      <td>138</td>\n",
       "      <td>94</td>\n",
       "      <td>299</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>F</td>\n",
       "      <td>22</td>\n",
       "      <td>351</td>\n",
       "      <td>24</td>\n",
       "      <td>317</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Department  Male Yes  Male No  Female Yes  Female No\n",
       "0          A       512      313          89         19\n",
       "1          B       353      207          17          8\n",
       "2          C       120      205         202        391\n",
       "3          D       138      279         131        244\n",
       "4          E        53      138          94        299\n",
       "5          F        22      351          24        317"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "file_name = 'https://joannabieri.com/introdatascience/data/berkley.csv'\n",
    "DF = pd.read_csv(file_name)\n",
    "display(DF)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2946022d-d2f3-45fb-9426-fbde15d6427d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-07T17:29:06.698551Z",
     "iopub.status.busy": "2026-10-07T17:29:06.698486Z",
     "iopub.status.idle": "2026-10-07T17:29:06.702584Z",
     "shell.execute_reply": "2026-10-07T17:29:06.702320Z"
    }
   },
   "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>Department</th>\n",
       "      <th>MF</th>\n",
       "      <th>Number</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>353</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>D</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>E</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>F</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>A</td>\n",
       "      <td>Male No</td>\n",
       "      <td>313</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>B</td>\n",
       "      <td>Male No</td>\n",
       "      <td>207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>C</td>\n",
       "      <td>Male No</td>\n",
       "      <td>205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>D</td>\n",
       "      <td>Male No</td>\n",
       "      <td>279</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>E</td>\n",
       "      <td>Male No</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>F</td>\n",
       "      <td>Male No</td>\n",
       "      <td>351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>A</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>B</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>C</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>D</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>E</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>F</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>A</td>\n",
       "      <td>Female No</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>B</td>\n",
       "      <td>Female No</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>C</td>\n",
       "      <td>Female No</td>\n",
       "      <td>391</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>D</td>\n",
       "      <td>Female No</td>\n",
       "      <td>244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>E</td>\n",
       "      <td>Female No</td>\n",
       "      <td>299</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>F</td>\n",
       "      <td>Female No</td>\n",
       "      <td>317</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Department          MF  Number\n",
       "0           A    Male Yes     512\n",
       "1           B    Male Yes     353\n",
       "2           C    Male Yes     120\n",
       "3           D    Male Yes     138\n",
       "4           E    Male Yes      53\n",
       "5           F    Male Yes      22\n",
       "6           A     Male No     313\n",
       "7           B     Male No     207\n",
       "8           C     Male No     205\n",
       "9           D     Male No     279\n",
       "10          E     Male No     138\n",
       "11          F     Male No     351\n",
       "12          A  Female Yes      89\n",
       "13          B  Female Yes      17\n",
       "14          C  Female Yes     202\n",
       "15          D  Female Yes     131\n",
       "16          E  Female Yes      94\n",
       "17          F  Female Yes      24\n",
       "18          A   Female No      19\n",
       "19          B   Female No       8\n",
       "20          C   Female No     391\n",
       "21          D   Female No     244\n",
       "22          E   Female No     299\n",
       "23          F   Female No     317"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DF_melt = pd.melt(DF,id_vars=['Department'],var_name='MF',value_name='Number')\n",
    "DF_melt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5d861ae5-ede6-4cfa-8a13-4b27e3de2b8e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-07T17:29:06.703870Z",
     "iopub.status.busy": "2026-10-07T17:29:06.703820Z",
     "iopub.status.idle": "2026-10-07T17:29:06.705640Z",
     "shell.execute_reply": "2026-10-07T17:29:06.705486Z"
    }
   },
   "outputs": [],
   "source": [
    "DF_melt['gender'] = DF_melt['MF'].apply(lambda x: x.split(' ')[0]).copy()\n",
    "DF_melt['admitted'] = DF_melt['MF'].apply(lambda x: x.split(' ')[1]).copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "632666dc-2519-4a29-8f2e-d84bfb94ab1e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-07T17:29:06.707346Z",
     "iopub.status.busy": "2026-10-07T17:29:06.707298Z",
     "iopub.status.idle": "2026-10-07T17:29:06.710002Z",
     "shell.execute_reply": "2026-10-07T17:29:06.709837Z"
    }
   },
   "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>Department</th>\n",
       "      <th>MF</th>\n",
       "      <th>Number</th>\n",
       "      <th>gender</th>\n",
       "      <th>admitted</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>512</td>\n",
       "      <td>Male</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>353</td>\n",
       "      <td>Male</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>120</td>\n",
       "      <td>Male</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>D</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>138</td>\n",
       "      <td>Male</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>E</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>53</td>\n",
       "      <td>Male</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>F</td>\n",
       "      <td>Male Yes</td>\n",
       "      <td>22</td>\n",
       "      <td>Male</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>A</td>\n",
       "      <td>Male No</td>\n",
       "      <td>313</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>B</td>\n",
       "      <td>Male No</td>\n",
       "      <td>207</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>C</td>\n",
       "      <td>Male No</td>\n",
       "      <td>205</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>D</td>\n",
       "      <td>Male No</td>\n",
       "      <td>279</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>E</td>\n",
       "      <td>Male No</td>\n",
       "      <td>138</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>F</td>\n",
       "      <td>Male No</td>\n",
       "      <td>351</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>A</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>89</td>\n",
       "      <td>Female</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>B</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>17</td>\n",
       "      <td>Female</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>C</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>202</td>\n",
       "      <td>Female</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>D</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>131</td>\n",
       "      <td>Female</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>E</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>94</td>\n",
       "      <td>Female</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>F</td>\n",
       "      <td>Female Yes</td>\n",
       "      <td>24</td>\n",
       "      <td>Female</td>\n",
       "      <td>Yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>A</td>\n",
       "      <td>Female No</td>\n",
       "      <td>19</td>\n",
       "      <td>Female</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>B</td>\n",
       "      <td>Female No</td>\n",
       "      <td>8</td>\n",
       "      <td>Female</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>C</td>\n",
       "      <td>Female No</td>\n",
       "      <td>391</td>\n",
       "      <td>Female</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>D</td>\n",
       "      <td>Female No</td>\n",
       "      <td>244</td>\n",
       "      <td>Female</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>E</td>\n",
       "      <td>Female No</td>\n",
       "      <td>299</td>\n",
       "      <td>Female</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>F</td>\n",
       "      <td>Female No</td>\n",
       "      <td>317</td>\n",
       "      <td>Female</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Department          MF  Number  gender admitted\n",
       "0           A    Male Yes     512    Male      Yes\n",
       "1           B    Male Yes     353    Male      Yes\n",
       "2           C    Male Yes     120    Male      Yes\n",
       "3           D    Male Yes     138    Male      Yes\n",
       "4           E    Male Yes      53    Male      Yes\n",
       "5           F    Male Yes      22    Male      Yes\n",
       "6           A     Male No     313    Male       No\n",
       "7           B     Male No     207    Male       No\n",
       "8           C     Male No     205    Male       No\n",
       "9           D     Male No     279    Male       No\n",
       "10          E     Male No     138    Male       No\n",
       "11          F     Male No     351    Male       No\n",
       "12          A  Female Yes      89  Female      Yes\n",
       "13          B  Female Yes      17  Female      Yes\n",
       "14          C  Female Yes     202  Female      Yes\n",
       "15          D  Female Yes     131  Female      Yes\n",
       "16          E  Female Yes      94  Female      Yes\n",
       "17          F  Female Yes      24  Female      Yes\n",
       "18          A   Female No      19  Female       No\n",
       "19          B   Female No       8  Female       No\n",
       "20          C   Female No     391  Female       No\n",
       "21          D   Female No     244  Female       No\n",
       "22          E   Female No     299  Female       No\n",
       "23          F   Female No     317  Female       No"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DF_melt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "432131a7-8956-4a5f-adee-ca0c59c0ff64",
   "metadata": {},
   "source": [
    "### Gender distribution by department\n",
    "\n",
    "What can we say about the gender distribution if we look at the individual departments.\n",
    "\n",
    "Start with our original \"melted\" data frame:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "022204a9-b9e4-4cc3-984f-d821c69b432b",
   "metadata": {},
   "source": [
    "#### Lets pivot!\n",
    "\n",
    "Pivot this data so that our departments become the column labels and our MF column becomes the index."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "af17b1d9-39d9-4fa7-9f03-619e4cca6639",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-07T17:29:06.711796Z",
     "iopub.status.busy": "2026-10-07T17:29:06.711743Z",
     "iopub.status.idle": "2026-10-07T17:29:06.712852Z",
     "shell.execute_reply": "2026-10-07T17:29:06.712669Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6f3a4052-70cb-45e1-9175-559660d97a6d",
   "metadata": {},
   "source": [
    "**Q2** Calculate the proportions for the other departments. We did department A in the lecture. You can use the code from the lecture or come up with your own way to do this. You can do this one by one or try using a FOR loop.\n",
    "\n",
    "Talk about what you see in these proportions. Which departments admit a large number of women? How do your number align with the visualization below?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0e45185f-febe-4dc8-9d2a-392cb154218d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-07T17:29:06.713751Z",
     "iopub.status.busy": "2026-10-07T17:29:06.713700Z",
     "iopub.status.idle": "2026-10-07T17:29:06.714884Z",
     "shell.execute_reply": "2026-10-07T17:29:06.714674Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1443020f-a431-4c9a-b5c7-7b47229b4614",
   "metadata": {},
   "source": [
    "### Here is a plot of the proportions data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fe801850-b1ab-4c10-b14a-5ddb8d1d6797",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-07T17:29:06.715479Z",
     "iopub.status.busy": "2026-10-07T17:29:06.715431Z",
     "iopub.status.idle": "2026-10-07T17:29:06.911473Z",
     "shell.execute_reply": "2026-10-07T17:29:06.911232Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "        <script>\n",
       "        window.PlotlyConfig = {MathJaxConfig: 'local'};\n",
       "        if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n",
       "        </script>\n",
       "        <script type=\"module\">import \"https://cdn.plot.ly/plotly-4.1.1.min\"</script>\n",
       "        "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div style=\"height:500px; width:800px;\">            <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-svg.min.js\"></script><script>if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script>                <script>window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
       "        <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-4.1.1.min.js\" integrity=\"sha256-O24V1F27f8pb0glCkelh3cVHLNiHAJ5gCaVtq2aNch8=\" crossorigin=\"anonymous\"></script>                <div id=\"ab44ebd0-3c42-49db-8f76-65e8d93f9236\" class=\"plotly-graph-div\" style=\"height:100%; width:100%;\"></div>            <script>                window.PLOTLYENV=window.PLOTLYENV || {};                                if (document.getElementById(\"ab44ebd0-3c42-49db-8f76-65e8d93f9236\")) {                    Plotly.newPlot(                        \"ab44ebd0-3c42-49db-8f76-65e8d93f9236\",                        [{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=Yes\\u003cbr\\u003eDepartment=A\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"Yes\",\"marker\":{\"color\":\"#2ca25f\",\"pattern\":{\"shape\":\"\"}},\"name\":\"Yes\",\"orientation\":\"h\",\"showlegend\":true,\"x\":{\"dtype\":\"i2\",\"bdata\":\"AAJZAA==\"},\"xaxis\":\"x5\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y5\",\"type\":\"histogram\"},{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=Yes\\u003cbr\\u003eDepartment=B\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"Yes\",\"marker\":{\"color\":\"#2ca25f\",\"pattern\":{\"shape\":\"\"}},\"name\":\"Yes\",\"orientation\":\"h\",\"showlegend\":false,\"x\":{\"dtype\":\"i2\",\"bdata\":\"YQERAA==\"},\"xaxis\":\"x6\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y6\",\"type\":\"histogram\"},{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=Yes\\u003cbr\\u003eDepartment=C\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"Yes\",\"marker\":{\"color\":\"#2ca25f\",\"pattern\":{\"shape\":\"\"}},\"name\":\"Yes\",\"orientation\":\"h\",\"showlegend\":false,\"x\":{\"dtype\":\"i2\",\"bdata\":\"eADKAA==\"},\"xaxis\":\"x3\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y3\",\"type\":\"histogram\"},{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=Yes\\u003cbr\\u003eDepartment=D\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"Yes\",\"marker\":{\"color\":\"#2ca25f\",\"pattern\":{\"shape\":\"\"}},\"name\":\"Yes\",\"orientation\":\"h\",\"showlegend\":false,\"x\":{\"dtype\":\"i2\",\"bdata\":\"igCDAA==\"},\"xaxis\":\"x4\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y4\",\"type\":\"histogram\"},{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=Yes\\u003cbr\\u003eDepartment=E\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"Yes\",\"marker\":{\"color\":\"#2ca25f\",\"pattern\":{\"shape\":\"\"}},\"name\":\"Yes\",\"orientation\":\"h\",\"showlegend\":false,\"x\":{\"dtype\":\"i1\",\"bdata\":\"NV4=\"},\"xaxis\":\"x\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y\",\"type\":\"histogram\"},{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=Yes\\u003cbr\\u003eDepartment=F\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"Yes\",\"marker\":{\"color\":\"#2ca25f\",\"pattern\":{\"shape\":\"\"}},\"name\":\"Yes\",\"orientation\":\"h\",\"showlegend\":false,\"x\":{\"dtype\":\"i1\",\"bdata\":\"Fhg=\"},\"xaxis\":\"x2\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y2\",\"type\":\"histogram\"},{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=No\\u003cbr\\u003eDepartment=A\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"No\",\"marker\":{\"color\":\"#99d8c9\",\"pattern\":{\"shape\":\"\"}},\"name\":\"No\",\"orientation\":\"h\",\"showlegend\":true,\"x\":{\"dtype\":\"i2\",\"bdata\":\"OQETAA==\"},\"xaxis\":\"x5\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y5\",\"type\":\"histogram\"},{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=No\\u003cbr\\u003eDepartment=B\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"No\",\"marker\":{\"color\":\"#99d8c9\",\"pattern\":{\"shape\":\"\"}},\"name\":\"No\",\"orientation\":\"h\",\"showlegend\":false,\"x\":{\"dtype\":\"i2\",\"bdata\":\"zwAIAA==\"},\"xaxis\":\"x6\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y6\",\"type\":\"histogram\"},{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=No\\u003cbr\\u003eDepartment=C\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"No\",\"marker\":{\"color\":\"#99d8c9\",\"pattern\":{\"shape\":\"\"}},\"name\":\"No\",\"orientation\":\"h\",\"showlegend\":false,\"x\":{\"dtype\":\"i2\",\"bdata\":\"zQCHAQ==\"},\"xaxis\":\"x3\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y3\",\"type\":\"histogram\"},{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=No\\u003cbr\\u003eDepartment=D\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"No\",\"marker\":{\"color\":\"#99d8c9\",\"pattern\":{\"shape\":\"\"}},\"name\":\"No\",\"orientation\":\"h\",\"showlegend\":false,\"x\":{\"dtype\":\"i2\",\"bdata\":\"FwH0AA==\"},\"xaxis\":\"x4\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y4\",\"type\":\"histogram\"},{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=No\\u003cbr\\u003eDepartment=E\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"No\",\"marker\":{\"color\":\"#99d8c9\",\"pattern\":{\"shape\":\"\"}},\"name\":\"No\",\"orientation\":\"h\",\"showlegend\":false,\"x\":{\"dtype\":\"i2\",\"bdata\":\"igArAQ==\"},\"xaxis\":\"x\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y\",\"type\":\"histogram\"},{\"bingroup\":\"y\",\"histfunc\":\"sum\",\"hovertemplate\":\"admitted=No\\u003cbr\\u003eDepartment=F\\u003cbr\\u003esum of Number (normalized as percent)=%{x}\\u003cbr\\u003egender=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"legendgroup\":\"No\",\"marker\":{\"color\":\"#99d8c9\",\"pattern\":{\"shape\":\"\"}},\"name\":\"No\",\"orientation\":\"h\",\"showlegend\":false,\"x\":{\"dtype\":\"i2\",\"bdata\":\"XwE9AQ==\"},\"xaxis\":\"x2\",\"y\":[\"Male\",\"Female\"],\"yaxis\":\"y2\",\"type\":\"histogram\"}],                        {\"template\":{\"data\":{\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"white\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"white\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"#C8D4E3\",\"linecolor\":\"#C8D4E3\",\"minorgridcolor\":\"#C8D4E3\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"#C8D4E3\",\"linecolor\":\"#C8D4E3\",\"minorgridcolor\":\"#C8D4E3\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"choropleth\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"choropleth\"}],\"contourcarpet\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"contourcarpet\"}],\"contour\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"contour\"}],\"heatmap\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"heatmap\"}],\"histogram2dcontour\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"histogram2dcontour\"}],\"histogram2d\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"histogram2d\"}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"mesh3d\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"mesh3d\"}],\"parcoords\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"parcoords\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}],\"scatter3d\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatter3d\"}],\"scattercarpet\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattercarpet\"}],\"scattergeo\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattergeo\"}],\"scattergl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattergl\"}],\"scattermap\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattermap\"}],\"scatterpolargl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterpolargl\"}],\"scatterpolar\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterpolar\"}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"scatterternary\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterternary\"}],\"surface\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"surface\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}]},\"layout\":{\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"autotypenumbers\":\"strict\",\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]],\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]},\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"geo\":{\"bgcolor\":\"white\",\"lakecolor\":\"white\",\"landcolor\":\"white\",\"showlakes\":true,\"showland\":true,\"subunitcolor\":\"#C8D4E3\"},\"hoverlabel\":{\"align\":\"left\"},\"hovermode\":\"closest\",\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"white\",\"polar\":{\"angularaxis\":{\"gridcolor\":\"#EBF0F8\",\"linecolor\":\"#EBF0F8\",\"ticks\":\"\"},\"bgcolor\":\"white\",\"radialaxis\":{\"gridcolor\":\"#EBF0F8\",\"linecolor\":\"#EBF0F8\",\"ticks\":\"\"}},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"white\",\"gridcolor\":\"#DFE8F3\",\"gridwidth\":2,\"linecolor\":\"#EBF0F8\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#EBF0F8\"},\"yaxis\":{\"backgroundcolor\":\"white\",\"gridcolor\":\"#DFE8F3\",\"gridwidth\":2,\"linecolor\":\"#EBF0F8\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#EBF0F8\"},\"zaxis\":{\"backgroundcolor\":\"white\",\"gridcolor\":\"#DFE8F3\",\"gridwidth\":2,\"linecolor\":\"#EBF0F8\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#EBF0F8\"}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"ternary\":{\"aaxis\":{\"gridcolor\":\"#DFE8F3\",\"linecolor\":\"#A2B1C6\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"#DFE8F3\",\"linecolor\":\"#A2B1C6\",\"ticks\":\"\"},\"bgcolor\":\"white\",\"caxis\":{\"gridcolor\":\"#DFE8F3\",\"linecolor\":\"#A2B1C6\",\"ticks\":\"\"}},\"title\":{\"x\":0.05},\"xaxis\":{\"automargin\":true,\"gridcolor\":\"#EBF0F8\",\"linecolor\":\"#EBF0F8\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"#EBF0F8\",\"zerolinewidth\":2},\"yaxis\":{\"automargin\":true,\"gridcolor\":\"#EBF0F8\",\"linecolor\":\"#EBF0F8\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"#EBF0F8\",\"zerolinewidth\":2}}},\"xaxis\":{\"anchor\":\"y\",\"domain\":[0.0,0.49],\"title\":{\"text\":\"\"}},\"yaxis\":{\"anchor\":\"x\",\"domain\":[0.0,0.2866666666666666],\"title\":{\"text\":\"Gender\"}},\"xaxis2\":{\"anchor\":\"y2\",\"domain\":[0.51,1.0],\"matches\":\"x\",\"title\":{\"text\":\"\"}},\"yaxis2\":{\"anchor\":\"x2\",\"domain\":[0.0,0.2866666666666666],\"matches\":\"y\",\"showticklabels\":false},\"xaxis3\":{\"anchor\":\"y3\",\"domain\":[0.0,0.49],\"matches\":\"x\",\"showticklabels\":false,\"title\":{\"text\":\"\"}},\"yaxis3\":{\"anchor\":\"x3\",\"domain\":[0.35666666666666663,0.6433333333333333],\"matches\":\"y\",\"title\":{\"text\":\"gender\"}},\"xaxis4\":{\"anchor\":\"y4\",\"domain\":[0.51,1.0],\"matches\":\"x\",\"showticklabels\":false,\"title\":{\"text\":\"\"}},\"yaxis4\":{\"anchor\":\"x4\",\"domain\":[0.35666666666666663,0.6433333333333333],\"matches\":\"y\",\"showticklabels\":false},\"xaxis5\":{\"anchor\":\"y5\",\"domain\":[0.0,0.49],\"matches\":\"x\",\"showticklabels\":false,\"title\":{\"text\":\"\"}},\"yaxis5\":{\"anchor\":\"x5\",\"domain\":[0.7133333333333333,0.9999999999999999],\"matches\":\"y\",\"title\":{\"text\":\"gender\"}},\"xaxis6\":{\"anchor\":\"y6\",\"domain\":[0.51,1.0],\"matches\":\"x\",\"showticklabels\":false,\"title\":{\"text\":\"\"}},\"yaxis6\":{\"anchor\":\"x6\",\"domain\":[0.7133333333333333,0.9999999999999999],\"matches\":\"y\",\"showticklabels\":false},\"annotations\":[{\"font\":{},\"showarrow\":false,\"text\":\"E\",\"x\":0.245,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":0.2866666666666666,\"yanchor\":\"bottom\",\"yref\":\"paper\"},{\"font\":{},\"showarrow\":false,\"text\":\"F\",\"x\":0.755,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":0.2866666666666666,\"yanchor\":\"bottom\",\"yref\":\"paper\"},{\"font\":{},\"showarrow\":false,\"text\":\"C\",\"x\":0.245,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":0.6433333333333333,\"yanchor\":\"bottom\",\"yref\":\"paper\"},{\"font\":{},\"showarrow\":false,\"text\":\"D\",\"x\":0.755,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":0.6433333333333333,\"yanchor\":\"bottom\",\"yref\":\"paper\"},{\"font\":{},\"showarrow\":false,\"text\":\"A\",\"x\":0.245,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":0.9999999999999999,\"yanchor\":\"bottom\",\"yref\":\"paper\"},{\"font\":{},\"showarrow\":false,\"text\":\"B\",\"x\":0.755,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":0.9999999999999999,\"yanchor\":\"bottom\",\"yref\":\"paper\"}],\"legend\":{\"title\":{\"text\":\"Admitted\"},\"tracegroupgap\":0},\"margin\":{\"t\":60},\"barmode\":\"relative\",\"barnorm\":\"percent\",\"title\":{\"text\":\"Percent male and female applications\",\"x\":0.5},\"autosize\":false,\"width\":800,\"height\":500},                        {\"responsive\": true}                    ).then(function(){\n",
       "                            \n",
       "var gd = document.getElementById('ab44ebd0-3c42-49db-8f76-65e8d93f9236');\n",
       "var x = new MutationObserver(function (mutations, observer) {{\n",
       "        var display = window.getComputedStyle(gd).display;\n",
       "        if (!display || display === 'none') {{\n",
       "            console.log([gd, 'removed!']);\n",
       "            Plotly.purge(gd);\n",
       "            observer.disconnect();\n",
       "        }}\n",
       "}});\n",
       "\n",
       "// Listen for the removal of the full notebook cells\n",
       "var notebookContainer = gd.closest('#notebook-container');\n",
       "if (notebookContainer) {{\n",
       "    x.observe(notebookContainer, {childList: true});\n",
       "}}\n",
       "\n",
       "// Listen for the clearing of the current output cell\n",
       "var outputEl = gd.closest('.output');\n",
       "if (outputEl) {{\n",
       "    x.observe(outputEl, {childList: true});\n",
       "}}\n",
       "\n",
       "                        })                };            </script>        </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = px.histogram(DF_melt,\n",
    "                   y='gender',\n",
    "                   x='Number',\n",
    "                   barnorm = \"percent\",\n",
    "                   color='admitted',\n",
    "                   facet_col='Department',\n",
    "                   facet_col_wrap=2,\n",
    "                   color_discrete_map = {'No':'#99d8c9','Yes':'#2ca25f'})\n",
    "\n",
    "fig.for_each_annotation(lambda a: a.update(text=a.text.split(\"=\")[1]))\n",
    "fig.update_xaxes(title_text='')\n",
    "\n",
    "fig.update_layout(title='Percent male and female applications',\n",
    "                  title_x=0.5,\n",
    "                  template=\"plotly_white\",\n",
    "                  xaxis_title=\"\",\n",
    "                  yaxis_title=\"Gender\",\n",
    "                  legend_title='Admitted',\n",
    "                  autosize=False,\n",
    "                  width=800,\n",
    "                  height=500)\n",
    "\n",
    "fig.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a40fab13-19ce-4835-8a0c-145796c99d93",
   "metadata": {},
   "source": [
    "------------------------\n",
    "------------------------\n",
    "\n",
    "## Homework - Exercises\n",
    "\n",
    "** Homework content and data from Data Science in a Box - he-05-legos.Rmd\n",
    "\n",
    "This week we'll do some data gymnastics to refresh and review what we learned over the past few weeks using (**simulated**) data from Lego sales in 2018 for a sample of customers who bought Legos in the US. This is different than the data we used on the Exam!\n",
    "\n",
    "\n",
    "### Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c5775204-ebb3-4e1c-a300-d4985aec01d5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-07T17:29:06.912751Z",
     "iopub.status.busy": "2026-10-07T17:29:06.912664Z",
     "iopub.status.idle": "2026-10-07T17:29:07.205579Z",
     "shell.execute_reply": "2026-10-07T17:29:07.205315Z"
    }
   },
   "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>first_name</th>\n",
       "      <th>last_name</th>\n",
       "      <th>age</th>\n",
       "      <th>phone_number</th>\n",
       "      <th>set_id</th>\n",
       "      <th>number</th>\n",
       "      <th>theme</th>\n",
       "      <th>subtheme</th>\n",
       "      <th>year</th>\n",
       "      <th>name</th>\n",
       "      <th>pieces</th>\n",
       "      <th>us_price</th>\n",
       "      <th>image_url</th>\n",
       "      <th>quantity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Kimberly</td>\n",
       "      <td>Beckstead</td>\n",
       "      <td>24</td>\n",
       "      <td>216-555-2549</td>\n",
       "      <td>24701</td>\n",
       "      <td>76062</td>\n",
       "      <td>DC Comics Super Heroes</td>\n",
       "      <td>Mighty Micros</td>\n",
       "      <td>2018</td>\n",
       "      <td>Robin vs. Bane</td>\n",
       "      <td>77.0</td>\n",
       "      <td>9.99</td>\n",
       "      <td>http://images.brickset.com/sets/images/76062-1...</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Neel</td>\n",
       "      <td>Garvin</td>\n",
       "      <td>35</td>\n",
       "      <td>819-555-3189</td>\n",
       "      <td>25626</td>\n",
       "      <td>70595</td>\n",
       "      <td>Ninjago</td>\n",
       "      <td>Rise of the Villains</td>\n",
       "      <td>2018</td>\n",
       "      <td>Ultra Stealth Raider</td>\n",
       "      <td>1093.0</td>\n",
       "      <td>119.99</td>\n",
       "      <td>http://images.brickset.com/sets/images/70595-1...</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Neel</td>\n",
       "      <td>Garvin</td>\n",
       "      <td>35</td>\n",
       "      <td>819-555-3189</td>\n",
       "      <td>24665</td>\n",
       "      <td>21031</td>\n",
       "      <td>Architecture</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018</td>\n",
       "      <td>Burj Khalifa</td>\n",
       "      <td>333.0</td>\n",
       "      <td>39.99</td>\n",
       "      <td>http://images.brickset.com/sets/images/21031-1...</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Chelsea</td>\n",
       "      <td>Bouchard</td>\n",
       "      <td>41</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24695</td>\n",
       "      <td>31048</td>\n",
       "      <td>Creator</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018</td>\n",
       "      <td>Lakeside Lodge</td>\n",
       "      <td>368.0</td>\n",
       "      <td>29.99</td>\n",
       "      <td>http://images.brickset.com/sets/images/31048-1...</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Chelsea</td>\n",
       "      <td>Bouchard</td>\n",
       "      <td>41</td>\n",
       "      <td>NaN</td>\n",
       "      <td>25626</td>\n",
       "      <td>70595</td>\n",
       "      <td>Ninjago</td>\n",
       "      <td>Rise of the Villains</td>\n",
       "      <td>2018</td>\n",
       "      <td>Ultra Stealth Raider</td>\n",
       "      <td>1093.0</td>\n",
       "      <td>119.99</td>\n",
       "      <td>http://images.brickset.com/sets/images/70595-1...</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>615</th>\n",
       "      <td>Talise</td>\n",
       "      <td>Nieukirk</td>\n",
       "      <td>16</td>\n",
       "      <td>801-555-2343</td>\n",
       "      <td>24902</td>\n",
       "      <td>41556</td>\n",
       "      <td>Mixels</td>\n",
       "      <td>Series 7</td>\n",
       "      <td>2018</td>\n",
       "      <td>Tiketz</td>\n",
       "      <td>62.0</td>\n",
       "      <td>4.99</td>\n",
       "      <td>http://images.brickset.com/sets/images/41556-1...</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>616</th>\n",
       "      <td>Spencer</td>\n",
       "      <td>Morgan</td>\n",
       "      <td>28</td>\n",
       "      <td>784-555-3455</td>\n",
       "      <td>26041</td>\n",
       "      <td>41580</td>\n",
       "      <td>Mixels</td>\n",
       "      <td>Series 9</td>\n",
       "      <td>2018</td>\n",
       "      <td>Myke</td>\n",
       "      <td>63.0</td>\n",
       "      <td>4.99</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>617</th>\n",
       "      <td>Spencer</td>\n",
       "      <td>Morgan</td>\n",
       "      <td>28</td>\n",
       "      <td>784-555-3455</td>\n",
       "      <td>26060</td>\n",
       "      <td>5005051</td>\n",
       "      <td>Gear</td>\n",
       "      <td>Digital Media</td>\n",
       "      <td>2018</td>\n",
       "      <td>Friends of Heartlake City Girlz 4 Life</td>\n",
       "      <td>NaN</td>\n",
       "      <td>19.99</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>618</th>\n",
       "      <td>Amelia</td>\n",
       "      <td>Hageman</td>\n",
       "      <td>40</td>\n",
       "      <td>336-555-1950</td>\n",
       "      <td>24702</td>\n",
       "      <td>76063</td>\n",
       "      <td>DC Comics Super Heroes</td>\n",
       "      <td>Mighty Micros</td>\n",
       "      <td>2018</td>\n",
       "      <td>The Flash vs. Captain Cold</td>\n",
       "      <td>88.0</td>\n",
       "      <td>9.99</td>\n",
       "      <td>http://images.brickset.com/sets/images/76063-1...</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>619</th>\n",
       "      <td>Amelia</td>\n",
       "      <td>Hageman</td>\n",
       "      <td>40</td>\n",
       "      <td>336-555-1950</td>\n",
       "      <td>24720</td>\n",
       "      <td>10830</td>\n",
       "      <td>Duplo</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018</td>\n",
       "      <td>Minnie's Café</td>\n",
       "      <td>27.0</td>\n",
       "      <td>19.99</td>\n",
       "      <td>http://images.brickset.com/sets/images/10830-1...</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>620 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    first_name  last_name  age  phone_number  set_id   number  \\\n",
       "0     Kimberly  Beckstead   24  216-555-2549   24701    76062   \n",
       "1         Neel     Garvin   35  819-555-3189   25626    70595   \n",
       "2         Neel     Garvin   35  819-555-3189   24665    21031   \n",
       "3      Chelsea   Bouchard   41           NaN   24695    31048   \n",
       "4      Chelsea   Bouchard   41           NaN   25626    70595   \n",
       "..         ...        ...  ...           ...     ...      ...   \n",
       "615     Talise   Nieukirk   16  801-555-2343   24902    41556   \n",
       "616    Spencer     Morgan   28  784-555-3455   26041    41580   \n",
       "617    Spencer     Morgan   28  784-555-3455   26060  5005051   \n",
       "618     Amelia    Hageman   40  336-555-1950   24702    76063   \n",
       "619     Amelia    Hageman   40  336-555-1950   24720    10830   \n",
       "\n",
       "                      theme              subtheme  year  \\\n",
       "0    DC Comics Super Heroes         Mighty Micros  2018   \n",
       "1                   Ninjago  Rise of the Villains  2018   \n",
       "2              Architecture                   NaN  2018   \n",
       "3                   Creator                   NaN  2018   \n",
       "4                   Ninjago  Rise of the Villains  2018   \n",
       "..                      ...                   ...   ...   \n",
       "615                  Mixels              Series 7  2018   \n",
       "616                  Mixels              Series 9  2018   \n",
       "617                    Gear         Digital Media  2018   \n",
       "618  DC Comics Super Heroes         Mighty Micros  2018   \n",
       "619                   Duplo                   NaN  2018   \n",
       "\n",
       "                                       name  pieces  us_price  \\\n",
       "0                            Robin vs. Bane    77.0      9.99   \n",
       "1                      Ultra Stealth Raider  1093.0    119.99   \n",
       "2                              Burj Khalifa   333.0     39.99   \n",
       "3                            Lakeside Lodge   368.0     29.99   \n",
       "4                      Ultra Stealth Raider  1093.0    119.99   \n",
       "..                                      ...     ...       ...   \n",
       "615                                  Tiketz    62.0      4.99   \n",
       "616                                    Myke    63.0      4.99   \n",
       "617  Friends of Heartlake City Girlz 4 Life     NaN     19.99   \n",
       "618              The Flash vs. Captain Cold    88.0      9.99   \n",
       "619                           Minnie's Café    27.0     19.99   \n",
       "\n",
       "                                             image_url  quantity  \n",
       "0    http://images.brickset.com/sets/images/76062-1...         1  \n",
       "1    http://images.brickset.com/sets/images/70595-1...         1  \n",
       "2    http://images.brickset.com/sets/images/21031-1...         1  \n",
       "3    http://images.brickset.com/sets/images/31048-1...         1  \n",
       "4    http://images.brickset.com/sets/images/70595-1...         1  \n",
       "..                                                 ...       ...  \n",
       "615  http://images.brickset.com/sets/images/41556-1...         2  \n",
       "616                                                NaN         2  \n",
       "617                                                NaN         1  \n",
       "618  http://images.brickset.com/sets/images/76063-1...         2  \n",
       "619  http://images.brickset.com/sets/images/10830-1...         4  \n",
       "\n",
       "[620 rows x 14 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file_name = 'https://joannabieri.com/introdatascience/data/lego-sales.csv'\n",
    "DF = pd.read_csv(file_name)\n",
    "DF"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2474002-893e-4c33-8229-d9fb8a3f4b29",
   "metadata": {},
   "source": [
    "### Exercises\n",
    "\n",
    "* Answer the following questions using reproducible Python code.\n",
    "* For each question, state your answer in a sentence, e.g. \"In this sample, the first three common names of purchasers are ...\".\n",
    "* Note that the answers to all questions are within the context of this particular sample of sales, i.e. you shouldn't make inferences about the population of all Lego sales based on this sample.\n",
    "\n",
    "-------------\n",
    "\n",
    "1.  Describe what you see in the data set (variables, observations, etc)\n",
    "\n",
    "2.  What are the three most common first names of purchasers?\n",
    "\n",
    "3.  What are the three most common themes of Lego sets purchased?\n",
    "\n",
    "4.  Among the most common theme of Lego sets purchased, what is the most common subtheme?\n",
    "\n",
    "5.  Create data frames for each of the ages in the following categories: \"18 and under\", \"19 - 25\", \"26 - 35\", \"36 - 50\", \"51 and over\". HINT - use masks and create separate data frames -OR- create a new column with these categorical labels (more advanced).\n",
    "\n",
    "6.  Which age group has purchased the highest number of Lego sets.\n",
    "\n",
    "7.  Which age group has spent the most money on Legos?\n",
    "\n",
    "8.  Which Lego theme has made the most money for Lego? HINT: Simpler than #5, just use a groupby()\n",
    "\n",
    "9.  Which area code has spent the most money on Legos? In the US the area code is the first 3 digits of a phone number. HINT: You will need to split the phone number and get just the first three. You decide what to do about reporting the NaNs.\n",
    "\n",
    "10.  Come up with a question you want to answer using these data, and write it down. Then, create a data visualization that answers the question, and explain how your visualization answers the question."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "776800ff-22b6-48c3-8789-fd8a0a4f948d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
