{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2eac3f7d-62ee-4545-9a96-b3d5aacc4da4",
   "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 6\n",
    "---------------------------------------\n",
    "\n",
    "GOALS:\n",
    "\n",
    "1. Answer all the questions from the lecture.\n",
    "2. Practice wrangling data - doing more advanced code\n",
    "3. Complete your first more advanced Exploration/Exercise\n",
    "\n",
    "----------------------------------------------------------\n",
    "\n",
    "This homework has **4 Questions** and **7 Exercises**\n",
    "\n",
    "NOTE:\n",
    "Exercises will tend to be an analysis of a single piece of data where one exercise builds on the next.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "85d851b3-4123-484c-a51a-561490abcc68",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:45.148872Z",
     "iopub.status.busy": "2026-09-09T23:21:45.148699Z",
     "iopub.status.idle": "2026-09-09T23:21:46.791815Z",
     "shell.execute_reply": "2026-09-09T23:21:46.791194Z"
    }
   },
   "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"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "40945f6e-1a32-4c95-9a56-686a09db83f2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:46.793553Z",
     "iopub.status.busy": "2026-09-09T23:21:46.793384Z",
     "iopub.status.idle": "2026-09-09T23:21:49.622065Z",
     "shell.execute_reply": "2026-09-09T23:21:49.621456Z"
    }
   },
   "outputs": [],
   "source": [
    "file_location = 'https://joannabieri.com/introdatascience/data/hotels.csv'\n",
    "DF_raw_hotels = pd.read_csv(file_location)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cf9bcb7c-2440-4651-aad0-d27e779933f6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.623756Z",
     "iopub.status.busy": "2026-09-09T23:21:49.623580Z",
     "iopub.status.idle": "2026-09-09T23:21:49.664408Z",
     "shell.execute_reply": "2026-09-09T23:21:49.663859Z"
    }
   },
   "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>hotel</th>\n",
       "      <th>is_canceled</th>\n",
       "      <th>lead_time</th>\n",
       "      <th>arrival_date_year</th>\n",
       "      <th>arrival_date_month</th>\n",
       "      <th>arrival_date_week_number</th>\n",
       "      <th>arrival_date_day_of_month</th>\n",
       "      <th>stays_in_weekend_nights</th>\n",
       "      <th>stays_in_week_nights</th>\n",
       "      <th>adults</th>\n",
       "      <th>...</th>\n",
       "      <th>deposit_type</th>\n",
       "      <th>agent</th>\n",
       "      <th>company</th>\n",
       "      <th>days_in_waiting_list</th>\n",
       "      <th>customer_type</th>\n",
       "      <th>adr</th>\n",
       "      <th>required_car_parking_spaces</th>\n",
       "      <th>total_of_special_requests</th>\n",
       "      <th>reservation_status</th>\n",
       "      <th>reservation_status_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>342</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>737</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>75.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>13</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>304.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>75.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>240.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>98.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119385</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>23</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>30</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>394.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>96.14</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119386</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>102</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>31</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>9.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>225.43</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119387</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>31</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>9.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>157.71</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119388</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>109</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>31</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>89.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>104.40</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119389</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>205</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>29</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>9.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>151.20</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-07</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>119390 rows × 32 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               hotel  is_canceled  lead_time  arrival_date_year  \\\n",
       "0       Resort Hotel            0        342               2015   \n",
       "1       Resort Hotel            0        737               2015   \n",
       "2       Resort Hotel            0          7               2015   \n",
       "3       Resort Hotel            0         13               2015   \n",
       "4       Resort Hotel            0         14               2015   \n",
       "...              ...          ...        ...                ...   \n",
       "119385    City Hotel            0         23               2017   \n",
       "119386    City Hotel            0        102               2017   \n",
       "119387    City Hotel            0         34               2017   \n",
       "119388    City Hotel            0        109               2017   \n",
       "119389    City Hotel            0        205               2017   \n",
       "\n",
       "       arrival_date_month  arrival_date_week_number  \\\n",
       "0                    July                        27   \n",
       "1                    July                        27   \n",
       "2                    July                        27   \n",
       "3                    July                        27   \n",
       "4                    July                        27   \n",
       "...                   ...                       ...   \n",
       "119385             August                        35   \n",
       "119386             August                        35   \n",
       "119387             August                        35   \n",
       "119388             August                        35   \n",
       "119389             August                        35   \n",
       "\n",
       "        arrival_date_day_of_month  stays_in_weekend_nights  \\\n",
       "0                               1                        0   \n",
       "1                               1                        0   \n",
       "2                               1                        0   \n",
       "3                               1                        0   \n",
       "4                               1                        0   \n",
       "...                           ...                      ...   \n",
       "119385                         30                        2   \n",
       "119386                         31                        2   \n",
       "119387                         31                        2   \n",
       "119388                         31                        2   \n",
       "119389                         29                        2   \n",
       "\n",
       "        stays_in_week_nights  adults  ...  deposit_type  agent company  \\\n",
       "0                          0       2  ...    No Deposit    NaN     NaN   \n",
       "1                          0       2  ...    No Deposit    NaN     NaN   \n",
       "2                          1       1  ...    No Deposit    NaN     NaN   \n",
       "3                          1       1  ...    No Deposit  304.0     NaN   \n",
       "4                          2       2  ...    No Deposit  240.0     NaN   \n",
       "...                      ...     ...  ...           ...    ...     ...   \n",
       "119385                     5       2  ...    No Deposit  394.0     NaN   \n",
       "119386                     5       3  ...    No Deposit    9.0     NaN   \n",
       "119387                     5       2  ...    No Deposit    9.0     NaN   \n",
       "119388                     5       2  ...    No Deposit   89.0     NaN   \n",
       "119389                     7       2  ...    No Deposit    9.0     NaN   \n",
       "\n",
       "       days_in_waiting_list customer_type     adr  \\\n",
       "0                         0     Transient    0.00   \n",
       "1                         0     Transient    0.00   \n",
       "2                         0     Transient   75.00   \n",
       "3                         0     Transient   75.00   \n",
       "4                         0     Transient   98.00   \n",
       "...                     ...           ...     ...   \n",
       "119385                    0     Transient   96.14   \n",
       "119386                    0     Transient  225.43   \n",
       "119387                    0     Transient  157.71   \n",
       "119388                    0     Transient  104.40   \n",
       "119389                    0     Transient  151.20   \n",
       "\n",
       "        required_car_parking_spaces  total_of_special_requests  \\\n",
       "0                                 0                          0   \n",
       "1                                 0                          0   \n",
       "2                                 0                          0   \n",
       "3                                 0                          0   \n",
       "4                                 0                          1   \n",
       "...                             ...                        ...   \n",
       "119385                            0                          0   \n",
       "119386                            0                          2   \n",
       "119387                            0                          4   \n",
       "119388                            0                          0   \n",
       "119389                            0                          2   \n",
       "\n",
       "        reservation_status reservation_status_date  \n",
       "0                Check-Out              2015-07-01  \n",
       "1                Check-Out              2015-07-01  \n",
       "2                Check-Out              2015-07-02  \n",
       "3                Check-Out              2015-07-02  \n",
       "4                Check-Out              2015-07-03  \n",
       "...                    ...                     ...  \n",
       "119385           Check-Out              2017-09-06  \n",
       "119386           Check-Out              2017-09-07  \n",
       "119387           Check-Out              2017-09-07  \n",
       "119388           Check-Out              2017-09-07  \n",
       "119389           Check-Out              2017-09-07  \n",
       "\n",
       "[119390 rows x 32 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(DF_raw_hotels)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2bee57b5-06b5-4502-bb8c-f9e5470126e5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.666046Z",
     "iopub.status.busy": "2026-09-09T23:21:49.665872Z",
     "iopub.status.idle": "2026-09-09T23:21:49.668528Z",
     "shell.execute_reply": "2026-09-09T23:21:49.668021Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['hotel', 'is_canceled', 'lead_time', 'arrival_date_year', 'arrival_date_month', 'arrival_date_week_number', 'arrival_date_day_of_month', 'stays_in_weekend_nights', 'stays_in_week_nights', 'adults', 'children', 'babies', 'meal', 'country', 'market_segment', 'distribution_channel', 'is_repeated_guest', 'previous_cancellations', 'previous_bookings_not_canceled', 'reserved_room_type', 'assigned_room_type', 'booking_changes', 'deposit_type', 'agent', 'company', 'days_in_waiting_list', 'customer_type', 'adr', 'required_car_parking_spaces', 'total_of_special_requests', 'reservation_status', 'reservation_status_date']\n"
     ]
    }
   ],
   "source": [
    "# I always look at the column names - they have to be spelled exactly!\n",
    "columns_list = list(DF_raw_hotels.keys())\n",
    "print(columns_list)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb22b81a-8600-414d-aec8-5d8776ea6bde",
   "metadata": {},
   "source": [
    "### Example of Combining Masks\n",
    "\n",
    "* Show only results for visitors from USA or GBR."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e7ddf1a1-457b-4ba8-93f5-ad5e671e1700",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.670043Z",
     "iopub.status.busy": "2026-09-09T23:21:49.669884Z",
     "iopub.status.idle": "2026-09-09T23:21:49.701255Z",
     "shell.execute_reply": "2026-09-09T23:21:49.700742Z"
    }
   },
   "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>hotel</th>\n",
       "      <th>is_canceled</th>\n",
       "      <th>lead_time</th>\n",
       "      <th>arrival_date_year</th>\n",
       "      <th>arrival_date_month</th>\n",
       "      <th>arrival_date_week_number</th>\n",
       "      <th>arrival_date_day_of_month</th>\n",
       "      <th>stays_in_weekend_nights</th>\n",
       "      <th>stays_in_week_nights</th>\n",
       "      <th>adults</th>\n",
       "      <th>...</th>\n",
       "      <th>deposit_type</th>\n",
       "      <th>agent</th>\n",
       "      <th>company</th>\n",
       "      <th>days_in_waiting_list</th>\n",
       "      <th>customer_type</th>\n",
       "      <th>adr</th>\n",
       "      <th>required_car_parking_spaces</th>\n",
       "      <th>total_of_special_requests</th>\n",
       "      <th>reservation_status</th>\n",
       "      <th>reservation_status_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>75.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>13</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>304.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>75.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>240.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>98.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>240.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>98.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>68</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>240.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>97.00</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119358</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>135</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>30</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>14.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>143.10</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119369</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>207</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>34</td>\n",
       "      <td>25</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>14.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>96.25</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119378</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>247</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>31</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>42.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>86.85</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119379</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>109</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>31</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>9.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>155.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119388</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>109</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>31</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>No Deposit</td>\n",
       "      <td>89.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>104.40</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-07</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>14226 rows × 32 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               hotel  is_canceled  lead_time  arrival_date_year  \\\n",
       "2       Resort Hotel            0          7               2015   \n",
       "3       Resort Hotel            0         13               2015   \n",
       "4       Resort Hotel            0         14               2015   \n",
       "5       Resort Hotel            0         14               2015   \n",
       "12      Resort Hotel            0         68               2015   \n",
       "...              ...          ...        ...                ...   \n",
       "119358    City Hotel            0        135               2017   \n",
       "119369    City Hotel            0        207               2017   \n",
       "119378    City Hotel            0        247               2017   \n",
       "119379    City Hotel            0        109               2017   \n",
       "119388    City Hotel            0        109               2017   \n",
       "\n",
       "       arrival_date_month  arrival_date_week_number  \\\n",
       "2                    July                        27   \n",
       "3                    July                        27   \n",
       "4                    July                        27   \n",
       "5                    July                        27   \n",
       "12                   July                        27   \n",
       "...                   ...                       ...   \n",
       "119358             August                        35   \n",
       "119369             August                        34   \n",
       "119378             August                        35   \n",
       "119379             August                        35   \n",
       "119388             August                        35   \n",
       "\n",
       "        arrival_date_day_of_month  stays_in_weekend_nights  \\\n",
       "2                               1                        0   \n",
       "3                               1                        0   \n",
       "4                               1                        0   \n",
       "5                               1                        0   \n",
       "12                              1                        0   \n",
       "...                           ...                      ...   \n",
       "119358                         30                        1   \n",
       "119369                         25                        3   \n",
       "119378                         31                        1   \n",
       "119379                         31                        1   \n",
       "119388                         31                        2   \n",
       "\n",
       "        stays_in_week_nights  adults  ...  deposit_type  agent company  \\\n",
       "2                          1       1  ...    No Deposit    NaN     NaN   \n",
       "3                          1       1  ...    No Deposit  304.0     NaN   \n",
       "4                          2       2  ...    No Deposit  240.0     NaN   \n",
       "5                          2       2  ...    No Deposit  240.0     NaN   \n",
       "12                         4       2  ...    No Deposit  240.0     NaN   \n",
       "...                      ...     ...  ...           ...    ...     ...   \n",
       "119358                     4       2  ...    No Deposit   14.0     NaN   \n",
       "119369                     7       2  ...    No Deposit   14.0     NaN   \n",
       "119378                     3       2  ...    No Deposit   42.0     NaN   \n",
       "119379                     3       2  ...    No Deposit    9.0     NaN   \n",
       "119388                     5       2  ...    No Deposit   89.0     NaN   \n",
       "\n",
       "       days_in_waiting_list customer_type     adr  \\\n",
       "2                         0     Transient   75.00   \n",
       "3                         0     Transient   75.00   \n",
       "4                         0     Transient   98.00   \n",
       "5                         0     Transient   98.00   \n",
       "12                        0     Transient   97.00   \n",
       "...                     ...           ...     ...   \n",
       "119358                    0     Transient  143.10   \n",
       "119369                    0     Transient   96.25   \n",
       "119378                    0     Transient   86.85   \n",
       "119379                    0     Transient  155.00   \n",
       "119388                    0     Transient  104.40   \n",
       "\n",
       "        required_car_parking_spaces  total_of_special_requests  \\\n",
       "2                                 0                          0   \n",
       "3                                 0                          0   \n",
       "4                                 0                          1   \n",
       "5                                 0                          1   \n",
       "12                                0                          3   \n",
       "...                             ...                        ...   \n",
       "119358                            0                          1   \n",
       "119369                            0                          2   \n",
       "119378                            0                          0   \n",
       "119379                            0                          1   \n",
       "119388                            0                          0   \n",
       "\n",
       "        reservation_status reservation_status_date  \n",
       "2                Check-Out              2015-07-02  \n",
       "3                Check-Out              2015-07-02  \n",
       "4                Check-Out              2015-07-03  \n",
       "5                Check-Out              2015-07-03  \n",
       "12               Check-Out              2015-07-05  \n",
       "...                    ...                     ...  \n",
       "119358           Check-Out              2017-09-04  \n",
       "119369           Check-Out              2017-09-04  \n",
       "119378           Check-Out              2017-09-04  \n",
       "119379           Check-Out              2017-09-04  \n",
       "119388           Check-Out              2017-09-07  \n",
       "\n",
       "[14226 rows x 32 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mask = (DF_raw_hotels['country']=='USA') | (DF_raw_hotels['country']=='GBR')\n",
    "DF_raw_hotels[mask]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "375f4067-5efd-40c4-991f-6545c3f263ea",
   "metadata": {},
   "source": [
    "## Example Finding unique values\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ac44ea21-a1ec-4de5-9f42-fdfc5cb5a28c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.702858Z",
     "iopub.status.busy": "2026-09-09T23:21:49.702693Z",
     "iopub.status.idle": "2026-09-09T23:21:49.720771Z",
     "shell.execute_reply": "2026-09-09T23:21:49.720293Z"
    }
   },
   "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>market_segment</th>\n",
       "      <th>customer_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Direct</td>\n",
       "      <td>Transient</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Corporate</td>\n",
       "      <td>Transient</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Online TA</td>\n",
       "      <td>Transient</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Offline TA/TO</td>\n",
       "      <td>Transient</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>Offline TA/TO</td>\n",
       "      <td>Contract</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>Offline TA/TO</td>\n",
       "      <td>Transient-Party</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>125</th>\n",
       "      <td>Complementary</td>\n",
       "      <td>Transient</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>127</th>\n",
       "      <td>Online TA</td>\n",
       "      <td>Transient-Party</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>260</th>\n",
       "      <td>Direct</td>\n",
       "      <td>Transient-Party</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>413</th>\n",
       "      <td>Groups</td>\n",
       "      <td>Transient-Party</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>417</th>\n",
       "      <td>Groups</td>\n",
       "      <td>Transient</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>539</th>\n",
       "      <td>Online TA</td>\n",
       "      <td>Group</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1530</th>\n",
       "      <td>Corporate</td>\n",
       "      <td>Transient-Party</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1539</th>\n",
       "      <td>Direct</td>\n",
       "      <td>Group</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1587</th>\n",
       "      <td>Offline TA/TO</td>\n",
       "      <td>Group</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2262</th>\n",
       "      <td>Corporate</td>\n",
       "      <td>Contract</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2263</th>\n",
       "      <td>Direct</td>\n",
       "      <td>Contract</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2698</th>\n",
       "      <td>Groups</td>\n",
       "      <td>Contract</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9511</th>\n",
       "      <td>Complementary</td>\n",
       "      <td>Transient-Party</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14051</th>\n",
       "      <td>Complementary</td>\n",
       "      <td>Group</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14654</th>\n",
       "      <td>Groups</td>\n",
       "      <td>Group</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15141</th>\n",
       "      <td>Corporate</td>\n",
       "      <td>Group</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15261</th>\n",
       "      <td>Complementary</td>\n",
       "      <td>Contract</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15506</th>\n",
       "      <td>Online TA</td>\n",
       "      <td>Contract</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40600</th>\n",
       "      <td>Undefined</td>\n",
       "      <td>Transient-Party</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49013</th>\n",
       "      <td>Aviation</td>\n",
       "      <td>Transient-Party</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49372</th>\n",
       "      <td>Aviation</td>\n",
       "      <td>Transient</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112102</th>\n",
       "      <td>Aviation</td>\n",
       "      <td>Group</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       market_segment    customer_type\n",
       "0              Direct        Transient\n",
       "3           Corporate        Transient\n",
       "4           Online TA        Transient\n",
       "9       Offline TA/TO        Transient\n",
       "16      Offline TA/TO         Contract\n",
       "47      Offline TA/TO  Transient-Party\n",
       "125     Complementary        Transient\n",
       "127         Online TA  Transient-Party\n",
       "260            Direct  Transient-Party\n",
       "413            Groups  Transient-Party\n",
       "417            Groups        Transient\n",
       "539         Online TA            Group\n",
       "1530        Corporate  Transient-Party\n",
       "1539           Direct            Group\n",
       "1587    Offline TA/TO            Group\n",
       "2262        Corporate         Contract\n",
       "2263           Direct         Contract\n",
       "2698           Groups         Contract\n",
       "9511    Complementary  Transient-Party\n",
       "14051   Complementary            Group\n",
       "14654          Groups            Group\n",
       "15141       Corporate            Group\n",
       "15261   Complementary         Contract\n",
       "15506       Online TA         Contract\n",
       "40600       Undefined  Transient-Party\n",
       "49013        Aviation  Transient-Party\n",
       "49372        Aviation        Transient\n",
       "112102       Aviation            Group"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_columns = ['market_segment','customer_type']\n",
    "DF_raw_hotels[my_columns].drop_duplicates()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd184c04-061b-434d-ba4a-9460c5ceb25c",
   "metadata": {},
   "source": [
    "## Example Counting unique values\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "30dd04ac-3834-4805-ba5f-2b7f87d1ec9e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.722340Z",
     "iopub.status.busy": "2026-09-09T23:21:49.722175Z",
     "iopub.status.idle": "2026-09-09T23:21:49.732737Z",
     "shell.execute_reply": "2026-09-09T23:21:49.732388Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "market_segment\n",
       "Online TA         56477\n",
       "Offline TA/TO     24219\n",
       "Groups            19811\n",
       "Direct            12606\n",
       "Corporate          5295\n",
       "Complementary       743\n",
       "Aviation            237\n",
       "Undefined             2\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_columns = ['market_segment']\n",
    "DF_raw_hotels[my_columns].value_counts()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1593bee-5c60-4538-9fa9-12527fc6d2ea",
   "metadata": {},
   "source": [
    "## Example of Counting unique values in two columns - unsorted\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2e61352f-d003-4879-b60a-dde3f6c19751",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.734224Z",
     "iopub.status.busy": "2026-09-09T23:21:49.734070Z",
     "iopub.status.idle": "2026-09-09T23:21:49.751411Z",
     "shell.execute_reply": "2026-09-09T23:21:49.750993Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "market_segment  customer_type  \n",
       "Aviation        Group                  2\n",
       "                Transient            218\n",
       "                Transient-Party       17\n",
       "Complementary   Contract               2\n",
       "                Group                  6\n",
       "                Transient            703\n",
       "                Transient-Party       32\n",
       "Corporate       Contract              22\n",
       "                Group                 29\n",
       "                Transient           3576\n",
       "                Transient-Party     1668\n",
       "Direct          Contract              14\n",
       "                Group                134\n",
       "                Transient          11336\n",
       "                Transient-Party     1122\n",
       "Groups          Contract             735\n",
       "                Group                 16\n",
       "                Transient           8427\n",
       "                Transient-Party    10633\n",
       "Offline TA/TO   Contract            1817\n",
       "                Group                211\n",
       "                Transient          14054\n",
       "                Transient-Party     8137\n",
       "Online TA       Contract            1486\n",
       "                Group                179\n",
       "                Transient          51299\n",
       "                Transient-Party     3513\n",
       "Undefined       Transient-Party        2\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_columns = ['market_segment','customer_type']\n",
    "DF_raw_hotels[my_columns].value_counts(sort=False)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c2350169-ed73-4089-8fed-9484ec05e923",
   "metadata": {},
   "source": [
    "## Example of Saving Unique Values to a Data Frame\n",
    "\n",
    "Just add the command **.reset_index().rename(columns={\"index\": \"value\", 0: \"count\"})**. In this class "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a1b8e743-cc66-4290-97fa-2a7cad2bb510",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.752961Z",
     "iopub.status.busy": "2026-09-09T23:21:49.752804Z",
     "iopub.status.idle": "2026-09-09T23:21:49.772929Z",
     "shell.execute_reply": "2026-09-09T23:21:49.772395Z"
    }
   },
   "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>market_segment</th>\n",
       "      <th>customer_type</th>\n",
       "      <th>count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Online TA</td>\n",
       "      <td>Transient</td>\n",
       "      <td>51299</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Offline TA/TO</td>\n",
       "      <td>Transient</td>\n",
       "      <td>14054</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Direct</td>\n",
       "      <td>Transient</td>\n",
       "      <td>11336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Groups</td>\n",
       "      <td>Transient-Party</td>\n",
       "      <td>10633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Groups</td>\n",
       "      <td>Transient</td>\n",
       "      <td>8427</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Offline TA/TO</td>\n",
       "      <td>Transient-Party</td>\n",
       "      <td>8137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Corporate</td>\n",
       "      <td>Transient</td>\n",
       "      <td>3576</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Online TA</td>\n",
       "      <td>Transient-Party</td>\n",
       "      <td>3513</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Offline TA/TO</td>\n",
       "      <td>Contract</td>\n",
       "      <td>1817</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Corporate</td>\n",
       "      <td>Transient-Party</td>\n",
       "      <td>1668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Online TA</td>\n",
       "      <td>Contract</td>\n",
       "      <td>1486</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Direct</td>\n",
       "      <td>Transient-Party</td>\n",
       "      <td>1122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>Groups</td>\n",
       "      <td>Contract</td>\n",
       "      <td>735</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>Complementary</td>\n",
       "      <td>Transient</td>\n",
       "      <td>703</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>Aviation</td>\n",
       "      <td>Transient</td>\n",
       "      <td>218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>Offline TA/TO</td>\n",
       "      <td>Group</td>\n",
       "      <td>211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>Online TA</td>\n",
       "      <td>Group</td>\n",
       "      <td>179</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>Direct</td>\n",
       "      <td>Group</td>\n",
       "      <td>134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>Complementary</td>\n",
       "      <td>Transient-Party</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>Corporate</td>\n",
       "      <td>Group</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>Corporate</td>\n",
       "      <td>Contract</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>Aviation</td>\n",
       "      <td>Transient-Party</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>Groups</td>\n",
       "      <td>Group</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>Direct</td>\n",
       "      <td>Contract</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>Complementary</td>\n",
       "      <td>Group</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>Complementary</td>\n",
       "      <td>Contract</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>Aviation</td>\n",
       "      <td>Group</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>Undefined</td>\n",
       "      <td>Transient-Party</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   market_segment    customer_type  count\n",
       "0       Online TA        Transient  51299\n",
       "1   Offline TA/TO        Transient  14054\n",
       "2          Direct        Transient  11336\n",
       "3          Groups  Transient-Party  10633\n",
       "4          Groups        Transient   8427\n",
       "5   Offline TA/TO  Transient-Party   8137\n",
       "6       Corporate        Transient   3576\n",
       "7       Online TA  Transient-Party   3513\n",
       "8   Offline TA/TO         Contract   1817\n",
       "9       Corporate  Transient-Party   1668\n",
       "10      Online TA         Contract   1486\n",
       "11         Direct  Transient-Party   1122\n",
       "12         Groups         Contract    735\n",
       "13  Complementary        Transient    703\n",
       "14       Aviation        Transient    218\n",
       "15  Offline TA/TO            Group    211\n",
       "16      Online TA            Group    179\n",
       "17         Direct            Group    134\n",
       "18  Complementary  Transient-Party     32\n",
       "19      Corporate            Group     29\n",
       "20      Corporate         Contract     22\n",
       "21       Aviation  Transient-Party     17\n",
       "22         Groups            Group     16\n",
       "23         Direct         Contract     14\n",
       "24  Complementary            Group      6\n",
       "25  Complementary         Contract      2\n",
       "26       Aviation            Group      2\n",
       "27      Undefined  Transient-Party      2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "my_columns = ['market_segment','customer_type']\n",
    "my_counts = DF_raw_hotels[my_columns].value_counts()\n",
    "my_counts = my_counts.reset_index().rename(columns={\"index\": \"value\", 0: \"count\"})\n",
    "display(my_counts)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4113401c-1059-464c-bc4f-6787bf224f50",
   "metadata": {},
   "source": [
    "## Example of Adding a column to a Data Frame\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ace7c62a-4085-43bb-b4d0-677f39bfa9f1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.774507Z",
     "iopub.status.busy": "2026-09-09T23:21:49.774346Z",
     "iopub.status.idle": "2026-09-09T23:21:49.810121Z",
     "shell.execute_reply": "2026-09-09T23:21:49.809681Z"
    }
   },
   "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>hotel</th>\n",
       "      <th>is_canceled</th>\n",
       "      <th>lead_time</th>\n",
       "      <th>arrival_date_year</th>\n",
       "      <th>arrival_date_month</th>\n",
       "      <th>arrival_date_week_number</th>\n",
       "      <th>arrival_date_day_of_month</th>\n",
       "      <th>stays_in_weekend_nights</th>\n",
       "      <th>stays_in_week_nights</th>\n",
       "      <th>adults</th>\n",
       "      <th>...</th>\n",
       "      <th>agent</th>\n",
       "      <th>company</th>\n",
       "      <th>days_in_waiting_list</th>\n",
       "      <th>customer_type</th>\n",
       "      <th>adr</th>\n",
       "      <th>required_car_parking_spaces</th>\n",
       "      <th>total_of_special_requests</th>\n",
       "      <th>reservation_status</th>\n",
       "      <th>reservation_status_date</th>\n",
       "      <th>little_ones</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>342</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-01</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>737</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-01</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>75.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-02</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>13</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>304.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>75.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-02</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Resort Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>2015</td>\n",
       "      <td>July</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>240.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>98.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2015-07-03</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119385</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>23</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>30</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>394.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>96.14</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-06</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119386</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>102</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>31</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>9.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>225.43</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-07</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119387</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>31</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>9.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>157.71</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-07</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119388</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>109</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>31</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>89.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>104.40</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-07</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119389</th>\n",
       "      <td>City Hotel</td>\n",
       "      <td>0</td>\n",
       "      <td>205</td>\n",
       "      <td>2017</td>\n",
       "      <td>August</td>\n",
       "      <td>35</td>\n",
       "      <td>29</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>9.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>Transient</td>\n",
       "      <td>151.20</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>Check-Out</td>\n",
       "      <td>2017-09-07</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>119390 rows × 33 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               hotel  is_canceled  lead_time  arrival_date_year  \\\n",
       "0       Resort Hotel            0        342               2015   \n",
       "1       Resort Hotel            0        737               2015   \n",
       "2       Resort Hotel            0          7               2015   \n",
       "3       Resort Hotel            0         13               2015   \n",
       "4       Resort Hotel            0         14               2015   \n",
       "...              ...          ...        ...                ...   \n",
       "119385    City Hotel            0         23               2017   \n",
       "119386    City Hotel            0        102               2017   \n",
       "119387    City Hotel            0         34               2017   \n",
       "119388    City Hotel            0        109               2017   \n",
       "119389    City Hotel            0        205               2017   \n",
       "\n",
       "       arrival_date_month  arrival_date_week_number  \\\n",
       "0                    July                        27   \n",
       "1                    July                        27   \n",
       "2                    July                        27   \n",
       "3                    July                        27   \n",
       "4                    July                        27   \n",
       "...                   ...                       ...   \n",
       "119385             August                        35   \n",
       "119386             August                        35   \n",
       "119387             August                        35   \n",
       "119388             August                        35   \n",
       "119389             August                        35   \n",
       "\n",
       "        arrival_date_day_of_month  stays_in_weekend_nights  \\\n",
       "0                               1                        0   \n",
       "1                               1                        0   \n",
       "2                               1                        0   \n",
       "3                               1                        0   \n",
       "4                               1                        0   \n",
       "...                           ...                      ...   \n",
       "119385                         30                        2   \n",
       "119386                         31                        2   \n",
       "119387                         31                        2   \n",
       "119388                         31                        2   \n",
       "119389                         29                        2   \n",
       "\n",
       "        stays_in_week_nights  adults  ...  agent  company  \\\n",
       "0                          0       2  ...    NaN      NaN   \n",
       "1                          0       2  ...    NaN      NaN   \n",
       "2                          1       1  ...    NaN      NaN   \n",
       "3                          1       1  ...  304.0      NaN   \n",
       "4                          2       2  ...  240.0      NaN   \n",
       "...                      ...     ...  ...    ...      ...   \n",
       "119385                     5       2  ...  394.0      NaN   \n",
       "119386                     5       3  ...    9.0      NaN   \n",
       "119387                     5       2  ...    9.0      NaN   \n",
       "119388                     5       2  ...   89.0      NaN   \n",
       "119389                     7       2  ...    9.0      NaN   \n",
       "\n",
       "       days_in_waiting_list customer_type     adr required_car_parking_spaces  \\\n",
       "0                         0     Transient    0.00                           0   \n",
       "1                         0     Transient    0.00                           0   \n",
       "2                         0     Transient   75.00                           0   \n",
       "3                         0     Transient   75.00                           0   \n",
       "4                         0     Transient   98.00                           0   \n",
       "...                     ...           ...     ...                         ...   \n",
       "119385                    0     Transient   96.14                           0   \n",
       "119386                    0     Transient  225.43                           0   \n",
       "119387                    0     Transient  157.71                           0   \n",
       "119388                    0     Transient  104.40                           0   \n",
       "119389                    0     Transient  151.20                           0   \n",
       "\n",
       "        total_of_special_requests  reservation_status  \\\n",
       "0                               0           Check-Out   \n",
       "1                               0           Check-Out   \n",
       "2                               0           Check-Out   \n",
       "3                               0           Check-Out   \n",
       "4                               1           Check-Out   \n",
       "...                           ...                 ...   \n",
       "119385                          0           Check-Out   \n",
       "119386                          2           Check-Out   \n",
       "119387                          4           Check-Out   \n",
       "119388                          0           Check-Out   \n",
       "119389                          2           Check-Out   \n",
       "\n",
       "        reservation_status_date little_ones  \n",
       "0                    2015-07-01         0.0  \n",
       "1                    2015-07-01         0.0  \n",
       "2                    2015-07-02         0.0  \n",
       "3                    2015-07-02         0.0  \n",
       "4                    2015-07-03         0.0  \n",
       "...                         ...         ...  \n",
       "119385               2017-09-06         0.0  \n",
       "119386               2017-09-07         0.0  \n",
       "119387               2017-09-07         0.0  \n",
       "119388               2017-09-07         0.0  \n",
       "119389               2017-09-07         0.0  \n",
       "\n",
       "[119390 rows x 33 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DF_raw_hotels['little_ones'] = DF_raw_hotels['children'] + DF_raw_hotels['babies']\n",
    "DF_raw_hotels\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d7ce457a-38c5-48b2-97ee-eecc6af9bf0e",
   "metadata": {},
   "source": [
    "**Q1** Count up the number of little_ones in different hotel types (Hint - use value_counts() with hotel and little_ones as your columns.)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "342b5502-ab88-49d0-9dcb-862a7f8602b8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.811798Z",
     "iopub.status.busy": "2026-09-09T23:21:49.811625Z",
     "iopub.status.idle": "2026-09-09T23:21:49.813737Z",
     "shell.execute_reply": "2026-09-09T23:21:49.813332Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here:\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b1b52ae-36e1-49c1-bd1b-30165cbfd0ce",
   "metadata": {},
   "source": [
    "**Q2** Add a new column that calculates the total number of humans (all_humans) in the room (adults+children+babies) (Hint - you can copy and paste the code above where we calculated little_ones and add on another thing)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "70ba2273-7186-46c1-8e4d-87bdaa7f6b78",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.815223Z",
     "iopub.status.busy": "2026-09-09T23:21:49.815075Z",
     "iopub.status.idle": "2026-09-09T23:21:49.817019Z",
     "shell.execute_reply": "2026-09-09T23:21:49.816609Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41bea042-6828-4b52-a156-82e7b7ccf21e",
   "metadata": {},
   "source": [
    "**Q3** Can you figure out what the code below is doing - comment on each line, remember you can add a comment using the hashtag #"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "353b836e-d2ab-472d-a483-466ca5d08178",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.818473Z",
     "iopub.status.busy": "2026-09-09T23:21:49.818326Z",
     "iopub.status.idle": "2026-09-09T23:21:49.831985Z",
     "shell.execute_reply": "2026-09-09T23:21:49.831485Z"
    }
   },
   "outputs": [],
   "source": [
    "# PLEASE ADD YOUR COMMENTS!\n",
    "DF_raw_hotels['little_ones'] = DF_raw_hotels['children'] + DF_raw_hotels['babies']\n",
    "my_columns = ['hotel','little_ones']\n",
    "my_counts = DF_raw_hotels[my_columns].value_counts()\n",
    "my_counts = my_counts.reset_index().rename(columns={\"index\": \"value\", 0: \"count\"})\n",
    "my_counts['proportion']=my_counts['count']/sum(my_counts['count'])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cee2cacf-ced0-4919-8365-4f9dc747a190",
   "metadata": {},
   "source": [
    "## Example of Grouping the data frame into chunks\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "40f5b055-efcf-42ef-a2c2-9cd5e4dcf37e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.833523Z",
     "iopub.status.busy": "2026-09-09T23:21:49.833369Z",
     "iopub.status.idle": "2026-09-09T23:21:49.846924Z",
     "shell.execute_reply": "2026-09-09T23:21:49.846571Z"
    }
   },
   "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>adults</th>\n",
       "      <th>children</th>\n",
       "      <th>little_ones</th>\n",
       "      <th>babies</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>hotel</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>City Hotel</th>\n",
       "      <td>146838</td>\n",
       "      <td>7248.0</td>\n",
       "      <td>7640.0</td>\n",
       "      <td>392</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Resort Hotel</th>\n",
       "      <td>74798</td>\n",
       "      <td>5155.0</td>\n",
       "      <td>5712.0</td>\n",
       "      <td>557</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              adults  children  little_ones  babies\n",
       "hotel                                              \n",
       "City Hotel    146838    7248.0       7640.0     392\n",
       "Resort Hotel   74798    5155.0       5712.0     557"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_columns = ['adults','children','little_ones','babies']\n",
    "DF_raw_hotels.groupby(by=['hotel'])[my_columns].sum()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "81237655-f899-49ee-a158-2fac73e8441e",
   "metadata": {},
   "source": [
    "There are lots of different operations you could use:\n",
    "\n",
    "* .min()\n",
    "* .max()\n",
    "* .mean()\n",
    "* .median()\n",
    "* .sum()\n",
    "* .prod()\n",
    "* .count()\n",
    "* .describe()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8caf0e2c-79db-49d1-8869-cc69aaf611e6",
   "metadata": {},
   "source": [
    "Here we see that .describe() does all the descriptive statistics for each of columns, broken into the two groups. \n",
    "\n",
    "## Example of Grouping to quickly generate data\n",
    "\n",
    "The .groupby() function lets you quickly generate data about things you care about. In just one command below we are able to look at the total number of occupants for each of the columns (adults, children, little_ones, and babies) for each month in the data set."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "58542d27-8f84-4e03-b7e4-733c17e5b492",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.848466Z",
     "iopub.status.busy": "2026-09-09T23:21:49.848308Z",
     "iopub.status.idle": "2026-09-09T23:21:49.862659Z",
     "shell.execute_reply": "2026-09-09T23:21:49.862245Z"
    }
   },
   "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>adults</th>\n",
       "      <th>children</th>\n",
       "      <th>little_ones</th>\n",
       "      <th>babies</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>arrival_date_month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>April</th>\n",
       "      <td>20806</td>\n",
       "      <td>1141.0</td>\n",
       "      <td>1194.0</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>August</th>\n",
       "      <td>27795</td>\n",
       "      <td>2780.0</td>\n",
       "      <td>2976.0</td>\n",
       "      <td>196</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>December</th>\n",
       "      <td>12382</td>\n",
       "      <td>736.0</td>\n",
       "      <td>814.0</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>February</th>\n",
       "      <td>14450</td>\n",
       "      <td>790.0</td>\n",
       "      <td>849.0</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>January</th>\n",
       "      <td>10024</td>\n",
       "      <td>452.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>July</th>\n",
       "      <td>25164</td>\n",
       "      <td>2322.0</td>\n",
       "      <td>2443.0</td>\n",
       "      <td>121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>June</th>\n",
       "      <td>20353</td>\n",
       "      <td>1057.0</td>\n",
       "      <td>1128.0</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>March</th>\n",
       "      <td>17675</td>\n",
       "      <td>700.0</td>\n",
       "      <td>757.0</td>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>May</th>\n",
       "      <td>21539</td>\n",
       "      <td>845.0</td>\n",
       "      <td>917.0</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>November</th>\n",
       "      <td>11488</td>\n",
       "      <td>279.0</td>\n",
       "      <td>324.0</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>October</th>\n",
       "      <td>20279</td>\n",
       "      <td>703.0</td>\n",
       "      <td>765.0</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>September</th>\n",
       "      <td>19681</td>\n",
       "      <td>598.0</td>\n",
       "      <td>685.0</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    adults  children  little_ones  babies\n",
       "arrival_date_month                                       \n",
       "April                20806    1141.0       1194.0      53\n",
       "August               27795    2780.0       2976.0     196\n",
       "December             12382     736.0        814.0      78\n",
       "February             14450     790.0        849.0      59\n",
       "January              10024     452.0        500.0      48\n",
       "July                 25164    2322.0       2443.0     121\n",
       "June                 20353    1057.0       1128.0      71\n",
       "March                17675     700.0        757.0      57\n",
       "May                  21539     845.0        917.0      72\n",
       "November             11488     279.0        324.0      45\n",
       "October              20279     703.0        765.0      62\n",
       "September            19681     598.0        685.0      87"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DF_raw_hotels.groupby(by=['arrival_date_month'])[my_columns].sum()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40bdff93-753e-4212-bc44-4c2bbab99e86",
   "metadata": {},
   "source": [
    "**Q4** Try changing the code above to calculate the mean, max, and min for the above data."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12cdd392-d3d8-4252-ae65-3b5d0a74dd8d",
   "metadata": {},
   "source": [
    "# Exercises:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91449490-f20d-4395-96ed-7f1eca0dd943",
   "metadata": {},
   "source": [
    "## Our first big-ish problem:\n",
    "\n",
    "Now you will try to use our hotels data set to answer some questions! You will need to use the tools we have learned so far to look into the data and try to answer the questions. Really try to answer the questions with as few hints as possible!\n",
    "\n",
    "### IF YOU USE MY ANSWER - avoid plagiarism\n",
    "\n",
    "To avoid plagiarism, if you end up copying my answer and using it, YOU MUST explain clearly what each part of the code is doing. It's okay to need to use my code at this point, but it is not helpful to your learning to blindly copy and paste without trying to understand.\n",
    "\n",
    "**Hints and Answers can be found in the lecture notes!**\n",
    "\n",
    "### Exercise 1\n",
    "\n",
    "Are people traveling on a whim?\n",
    "\n",
    "How could you find out?\n",
    "\n",
    "Try creating a mask filtering for hotel bookings where the guest is **not** from the US (`country` code `\"USA\"`) and the `lead_time` is less than 1 day.\n",
    "\n",
    "What proportion of people traveled last minute?\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "bec396a5-58cc-4f0d-afb0-7c6a3f5412e3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.864334Z",
     "iopub.status.busy": "2026-09-09T23:21:49.864172Z",
     "iopub.status.idle": "2026-09-09T23:21:49.866367Z",
     "shell.execute_reply": "2026-09-09T23:21:49.865917Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ff3060b-6bf7-4580-ac3d-4e78b8d20ff5",
   "metadata": {},
   "source": [
    "### Exercise 2\n",
    "\n",
    "How many bookings involve at least 1 child **or** baby?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "9078b52e-a69d-4ede-ba0d-7851eea2c0a2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.867922Z",
     "iopub.status.busy": "2026-09-09T23:21:49.867710Z",
     "iopub.status.idle": "2026-09-09T23:21:49.869586Z",
     "shell.execute_reply": "2026-09-09T23:21:49.869247Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here:\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11fb134b-4ff6-4d33-b8a9-b19f6d502f36",
   "metadata": {},
   "source": [
    "### Exercise 3\n",
    "\n",
    "Do you think it's more likely to find bookings with children or babies in city hotels or resort hotels?\n",
    "Test your intuition.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c57b1e59-67e1-48fd-be59-06a6f4909ee5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.871070Z",
     "iopub.status.busy": "2026-09-09T23:21:49.870918Z",
     "iopub.status.idle": "2026-09-09T23:21:49.872741Z",
     "shell.execute_reply": "2026-09-09T23:21:49.872402Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here:\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80587774-3bfc-400d-b2b1-4e8188f8df4b",
   "metadata": {},
   "source": [
    "### Exercise 4\n",
    "\n",
    "Create a frequency table of the number of `adults` in a booking.\n",
    "Display the results in descending order so the most common observation is on top.\n",
    "What is the most common number of adults in bookings in this dataset?\n",
    "Are there any surprising results?\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "bd513df5-928a-48f8-b940-9edd18ff9d04",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.874191Z",
     "iopub.status.busy": "2026-09-09T23:21:49.874045Z",
     "iopub.status.idle": "2026-09-09T23:21:49.875795Z",
     "shell.execute_reply": "2026-09-09T23:21:49.875473Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here:\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d38741ad-d89a-469e-b528-995aab4b2027",
   "metadata": {},
   "source": [
    "### Exercise 5\n",
    "\n",
    "Repeat Exercise 4, once for canceled bookings (`is_canceled` coded as 1) and once for not canceled bookings (`is_canceled` coded as 0).\n",
    "What does this reveal about the surprising results you spotted in the previous exercise?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "888b434d-6d09-466b-bc49-9f52a5dc8fad",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.877277Z",
     "iopub.status.busy": "2026-09-09T23:21:49.877131Z",
     "iopub.status.idle": "2026-09-09T23:21:49.878893Z",
     "shell.execute_reply": "2026-09-09T23:21:49.878565Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here:\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6b87569-1f06-417f-916c-3cfc1de5739d",
   "metadata": {},
   "source": [
    "### Exercise 6\n",
    "\n",
    "Calculate minimum, mean, median, and maximum average daily rate (column labeled 'adr') grouped by `hotel` type so that you can get these statistics separately for resort and city hotels. (Hint - try using .describe() after doing group by)\n",
    "\n",
    "Which type of hotel is higher, on average?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "3e504f44-a5ac-45a9-8027-3d3fd8b80988",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.880359Z",
     "iopub.status.busy": "2026-09-09T23:21:49.880214Z",
     "iopub.status.idle": "2026-09-09T23:21:49.881959Z",
     "shell.execute_reply": "2026-09-09T23:21:49.881633Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here:\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11274118-dba5-44aa-b7fc-3b0fcdbe024d",
   "metadata": {},
   "source": [
    "### Exercise 7\n",
    "\n",
    "We observe two unusual values in the summary statistics above: a negative minimum, and a very high maximum.\n",
    "What types of hotels are these?\n",
    "\n",
    "Locate these observations in the data set and find out the arrival date (year and month) as well as how many people (adults, children, and babies) stayed in the room.\n",
    "\n",
    "You can investigate the data by showing the data frame to locate these values, but preferably you should identify them in a reproducible way with some code.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "14fb08c9-e48e-4745-a051-a95aeb788014",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-09T23:21:49.883366Z",
     "iopub.status.busy": "2026-09-09T23:21:49.883219Z",
     "iopub.status.idle": "2026-09-09T23:21:49.884990Z",
     "shell.execute_reply": "2026-09-09T23:21:49.884648Z"
    }
   },
   "outputs": [],
   "source": [
    "# Your code here: \n"
   ]
  }
 ],
 "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.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
