# data[].attributes.body
tng_jerrell@defence.gov.sg
week 6 task

# data[].attributes.body
Week 6 Assignment

# data[].attributes.attachment_link.readable_text
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python for Data Science using Pandas (Accessing Data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "gN2RFGn3VIJi"
   },
   "source": [
    "## Run The Following Code\n",
    "Hit SHIFT + ENTER when your cusor is inside the cell of code.<br/>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Numpy: A very brief intro"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> Create an array of 1,1,2,3,5,8 <br/>\n",
    "Compare with a list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "my_array = np.array([1,1,2,3,5,8])\n",
    "my_list = [1,1,2,3,5,8]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Array:  [1 1 2 3 5 8]\n",
      "List :  [1, 1, 2, 3, 5, 8]\n"
     ]
    }
   ],
   "source": [
    "print(\"Array: \",my_array)\n",
    "print(\"List : \",my_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> Check the type of my_array and my_list. <br/>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Array:  <class 'numpy.ndarray'>\n",
      "List :  <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "print(\"Array: \",type(my_array))\n",
    "print(\"List : \",type(my_list))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> perform NumPy math functions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "my_array = np.array([1,1,2,3,5,8])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "id": "T4KO-i82VIJk"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sum: 20\n",
      "min: 1\n",
      "max: 8\n",
      "mean: 3.3333333333333335\n",
      "var: 6.222222222222221\n"
     ]
    }
   ],
   "source": [
    "print('sum:', np.sum(my_array))\n",
    "print('min:', np.min(my_array))\n",
    "print('max:', np.max(my_array))\n",
    "print('mean:', np.mean(my_array))\n",
    "print('var:', np.var(my_array))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "dg1hBaA7VIJl"
   },
   "source": [
    "# Pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Reading data from common data files"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "3fskFP6UVIJo"
   },
   "source": [
    "> Data Preparation. Importing pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "id": "GChe2i8UVIJo"
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "vWc1F08eVIJp"
   },
   "source": [
    "> Open up an Excel file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "id": "iGnmXrx-VIJq"
   },
   "outputs": [],
   "source": [
    "hdb = 'data/0_raw_data/hdb_resale_sample_raw.xlsx'\n",
    "\n",
    "df = pd.read_excel(hdb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "gctnxHQEVIJo"
   },
   "source": [
    "> Open up a CSV file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "id": "1Wyy8PlXVIJp"
   },
   "outputs": [],
   "source": [
    "hdb = 'data/0_raw_data/hdb_resale_sample_raw.csv'\n",
    "\n",
    "df = pd.read_csv(hdb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "8oNcfodGVIJq"
   },
   "source": [
    "> viewing the contents of the dataset"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Understanding the data in DataFrame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The main dataset that we will work on is on HDB resale data.<br/>\n",
    "See the description below for the fields given. <br/>\n",
    "<br/>\n",
    "<table>\n",
    "    <tr><th>Field</th><th>Description</th></tr>\n",
    "    <tr><td>Trans_YearMonth</td><td>year-month (YYYY-MM) for transaction</td></tr>\n",
    "    <tr><td>town</td><td>town for the resale flat</td></tr>\n",
    "    <tr><td>flat_type</td><td>flat type for the resale flat</td></tr>\n",
    "    <tr><td>block</td><td>block for the resale flat</td></tr>\n",
    "    <tr><td>street_name</td><td>street for the resale flat</td></tr>\n",
    "    <tr><td>storey_range</td><td>year-month (YYYY-MM) for transaction</td></tr>\n",
    "    <tr><td>floor_area_sqm</td><td>floor area in square meter</td></tr>\n",
    "    <tr><td>flat_model</td><td>model of resale flat</td></tr>\n",
    "    <tr><td>lease_commence_date</td><td>year of lease commencement</td></tr>\n",
    "    <tr><td>resale_price</td><td>price of the resale flat</td></tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(15000, 10)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "id": "nB2DLyrQVIJq"
   },
   "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>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>39</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>260000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-08</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>289000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2016-11</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>250000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>250000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-10</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>200000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Tranc_YearMonth         town flat_type block    street_name storey_range  \\\n",
       "0         2015-03  JURONG EAST    3 ROOM    39  TEBAN GDNS RD     01 TO 03   \n",
       "1         2015-08  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "2         2016-11  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "3         2017-01  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "4         2017-10  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "\n",
       "   floor_area_sqm flat_model  lease_commence_date  resale_price  \n",
       "0            67.0   Improved                 1966      260000.0  \n",
       "1            67.0   Improved                 1966      289000.0  \n",
       "2            67.0   Improved                 1966      250000.0  \n",
       "3            67.0   Improved                 1966      250000.0  \n",
       "4            67.0   Improved                 1966      200000.0  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "4XA747EQVIJq"
   },
   "outputs": [],
   "source": [
    "df.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "id": "X9ZKDM4sVIJr"
   },
   "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>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>14995</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>JURONG WEST</td>\n",
       "      <td>5 ROOM</td>\n",
       "      <td>206</td>\n",
       "      <td>BOON LAY DR</td>\n",
       "      <td>19 TO 21</td>\n",
       "      <td>120.0</td>\n",
       "      <td>Standard</td>\n",
       "      <td>1976</td>\n",
       "      <td>495000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14996</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>JURONG WEST</td>\n",
       "      <td>5 ROOM</td>\n",
       "      <td>211</td>\n",
       "      <td>BOON LAY PL</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>130.0</td>\n",
       "      <td>Adjoined flat</td>\n",
       "      <td>1976</td>\n",
       "      <td>530000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14997</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>MARINE PARADE</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>67</td>\n",
       "      <td>MARINE DR</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>65.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1976</td>\n",
       "      <td>400000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14998</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>MARINE PARADE</td>\n",
       "      <td>4 ROOM</td>\n",
       "      <td>76</td>\n",
       "      <td>MARINE DR</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>82.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1976</td>\n",
       "      <td>540000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14999</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>MARINE PARADE</td>\n",
       "      <td>4 ROOM</td>\n",
       "      <td>62</td>\n",
       "      <td>MARINE DR</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>87.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1976</td>\n",
       "      <td>611888.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Tranc_YearMonth           town flat_type block  street_name  \\\n",
       "14995         2013-06    JURONG WEST    5 ROOM   206  BOON LAY DR   \n",
       "14996         2013-06    JURONG WEST    5 ROOM   211  BOON LAY PL   \n",
       "14997         2013-06  MARINE PARADE    3 ROOM    67    MARINE DR   \n",
       "14998         2013-06  MARINE PARADE    4 ROOM    76    MARINE DR   \n",
       "14999         2013-06  MARINE PARADE    4 ROOM    62    MARINE DR   \n",
       "\n",
       "      storey_range  floor_area_sqm     flat_model  lease_commence_date  \\\n",
       "14995     19 TO 21           120.0       Standard                 1976   \n",
       "14996     07 TO 09           130.0  Adjoined flat                 1976   \n",
       "14997     01 TO 03            65.0       Improved                 1976   \n",
       "14998     01 TO 03            82.0       Improved                 1976   \n",
       "14999     04 TO 06            87.0       Improved                 1976   \n",
       "\n",
       "       resale_price  \n",
       "14995      495000.0  \n",
       "14996      530000.0  \n",
       "14997      400000.0  \n",
       "14998      540000.0  \n",
       "14999      611888.0  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Tranc_YearMonth', 'town', 'flat_type', 'block', 'street_name',\n",
       "       'storey_range', 'floor_area_sqm', 'flat_model', 'lease_commence_date',\n",
       "       'resale_price'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Tranc_YearMonth',\n",
       " 'town',\n",
       " 'flat_type',\n",
       " 'block',\n",
       " 'street_name',\n",
       " 'storey_range',\n",
       " 'floor_area_sqm',\n",
       " 'flat_model',\n",
       " 'lease_commence_date',\n",
       " 'resale_price']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# return names of column as a list\n",
    "list(df.columns)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> Locating data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "id": "16JqmZT7VIJu",
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 15000 entries, 0 to 14999\n",
      "Data columns (total 10 columns):\n",
      " #   Column               Non-Null Count  Dtype  \n",
      "---  ------               --------------  -----  \n",
      " 0   Tranc_YearMonth      15000 non-null  object \n",
      " 1   town                 15000 non-null  object \n",
      " 2   flat_type            15000 non-null  object \n",
      " 3   block                15000 non-null  object \n",
      " 4   street_name          15000 non-null  object \n",
      " 5   storey_range         15000 non-null  object \n",
      " 6   floor_area_sqm       15000 non-null  float64\n",
      " 7   flat_model           15000 non-null  object \n",
      " 8   lease_commence_date  15000 non-null  int64  \n",
      " 9   resale_price         15000 non-null  float64\n",
      "dtypes: float64(2), int64(1), object(7)\n",
      "memory usage: 1.1+ MB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "id": "RtaSERBsVIJv"
   },
   "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>floor_area_sqm</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>15000.000000</td>\n",
       "      <td>15000.000000</td>\n",
       "      <td>1.500000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>69.900960</td>\n",
       "      <td>1972.663600</td>\n",
       "      <td>3.552616e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>17.976735</td>\n",
       "      <td>2.842588</td>\n",
       "      <td>1.296763e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>31.000000</td>\n",
       "      <td>1966.000000</td>\n",
       "      <td>1.400000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>60.000000</td>\n",
       "      <td>1970.000000</td>\n",
       "      <td>2.700000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>65.000000</td>\n",
       "      <td>1974.000000</td>\n",
       "      <td>3.200000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>75.000000</td>\n",
       "      <td>1975.000000</td>\n",
       "      <td>3.950000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>280.000000</td>\n",
       "      <td>1976.000000</td>\n",
       "      <td>1.185000e+06</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       floor_area_sqm  lease_commence_date  resale_price\n",
       "count    15000.000000         15000.000000  1.500000e+04\n",
       "mean        69.900960          1972.663600  3.552616e+05\n",
       "std         17.976735             2.842588  1.296763e+05\n",
       "min         31.000000          1966.000000  1.400000e+05\n",
       "25%         60.000000          1970.000000  2.700000e+05\n",
       "50%         65.000000          1974.000000  3.200000e+05\n",
       "75%         75.000000          1975.000000  3.950000e+05\n",
       "max        280.000000          1976.000000  1.185000e+06"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Accessing the Data by Columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        2015-03\n",
       "1        2015-08\n",
       "2        2016-11\n",
       "3        2017-01\n",
       "4        2017-10\n",
       "          ...   \n",
       "14995    2013-06\n",
       "14996    2013-06\n",
       "14997    2013-06\n",
       "14998    2013-06\n",
       "14999    2013-06\n",
       "Name: Tranc_YearMonth, Length: 15000, dtype: object"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Tranc_YearMonth']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(df['Tranc_YearMonth'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'JURONG EAST'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['town'][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03</td>\n",
       "      <td>JURONG EAST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-08</td>\n",
       "      <td>JURONG EAST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2016-11</td>\n",
       "      <td>JURONG EAST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01</td>\n",
       "      <td>JURONG EAST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-10</td>\n",
       "      <td>JURONG EAST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14995</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>JURONG WEST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14996</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>JURONG WEST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14997</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>MARINE PARADE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14998</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>MARINE PARADE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14999</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>MARINE PARADE</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>15000 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Tranc_YearMonth           town\n",
       "0             2015-03    JURONG EAST\n",
       "1             2015-08    JURONG EAST\n",
       "2             2016-11    JURONG EAST\n",
       "3             2017-01    JURONG EAST\n",
       "4             2017-10    JURONG EAST\n",
       "...               ...            ...\n",
       "14995         2013-06    JURONG WEST\n",
       "14996         2013-06    JURONG WEST\n",
       "14997         2013-06  MARINE PARADE\n",
       "14998         2013-06  MARINE PARADE\n",
       "14999         2013-06  MARINE PARADE\n",
       "\n",
       "[15000 rows x 2 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['Tranc_YearMonth','town']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(df[['Tranc_YearMonth','town']])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Understanding data in a column"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "qIkatepWVIJu"
   },
   "source": [
    "> Understanding data in a colum, using these methods\n",
    "> - info\n",
    "> - describe\n",
    "> - unique values\n",
    "> - value counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Improved', 'Standard', 'Adjoined flat', 'Terrace',\n",
       "       'New Generation'], dtype=object)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['flat_model'].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "id": "MKrGzwLZVIJw"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3 ROOM    11191\n",
       "4 ROOM     1947\n",
       "5 ROOM      942\n",
       "2 ROOM      821\n",
       "1 ROOM       99\n",
       "Name: flat_type, dtype: int64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['flat_type'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Accessing data by rows, using conditional statement(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          JURONG EAST\n",
       "1          JURONG EAST\n",
       "2          JURONG EAST\n",
       "3          JURONG EAST\n",
       "4          JURONG EAST\n",
       "             ...      \n",
       "14995      JURONG WEST\n",
       "14996      JURONG WEST\n",
       "14997    MARINE PARADE\n",
       "14998    MARINE PARADE\n",
       "14999    MARINE PARADE\n",
       "Name: town, Length: 15000, dtype: object"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# return a Series of the values in the town column (a collection objet that similar to LIST)\n",
    "df['town']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         True\n",
       "1         True\n",
       "2         True\n",
       "3         True\n",
       "4         True\n",
       "         ...  \n",
       "14995    False\n",
       "14996    False\n",
       "14997    False\n",
       "14998    False\n",
       "14999    False\n",
       "Name: town, Length: 15000, dtype: bool"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# use comparators (e.g., ==, !=, >=) to make this into a conditional statement\n",
    "df['town'] == 'JURONG EAST'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>39</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>260000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-08</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>289000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2016-11</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>250000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>250000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-10</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>200000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2017-11</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>232000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2018-01</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>38</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>235000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2018-06</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>226000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2018-09</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>215000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2019-07</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>39</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>218000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2019-09</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>39</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>220000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2020-01</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>220000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2020-03</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>38</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>210000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2020-08</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>39</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>228000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2020-12</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>230000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2013-01</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>39</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>315000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2013-04</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>311000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2013-07</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>38</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>310000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Tranc_YearMonth         town flat_type block    street_name storey_range  \\\n",
       "0          2015-03  JURONG EAST    3 ROOM    39  TEBAN GDNS RD     01 TO 03   \n",
       "1          2015-08  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "2          2016-11  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "3          2017-01  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "4          2017-10  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "5          2017-11  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "6          2018-01  JURONG EAST    3 ROOM    38  TEBAN GDNS RD     01 TO 03   \n",
       "7          2018-06  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "8          2018-09  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "9          2019-07  JURONG EAST    3 ROOM    39  TEBAN GDNS RD     01 TO 03   \n",
       "10         2019-09  JURONG EAST    3 ROOM    39  TEBAN GDNS RD     01 TO 03   \n",
       "11         2020-01  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "12         2020-03  JURONG EAST    3 ROOM    38  TEBAN GDNS RD     04 TO 06   \n",
       "13         2020-08  JURONG EAST    3 ROOM    39  TEBAN GDNS RD     04 TO 06   \n",
       "14         2020-12  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "15         2013-01  JURONG EAST    3 ROOM    39  TEBAN GDNS RD     01 TO 03   \n",
       "16         2013-04  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "17         2013-07  JURONG EAST    3 ROOM    38  TEBAN GDNS RD     01 TO 03   \n",
       "\n",
       "    floor_area_sqm flat_model  lease_commence_date  resale_price  \n",
       "0             67.0   Improved                 1966      260000.0  \n",
       "1             67.0   Improved                 1966      289000.0  \n",
       "2             67.0   Improved                 1966      250000.0  \n",
       "3             67.0   Improved                 1966      250000.0  \n",
       "4             67.0   Improved                 1966      200000.0  \n",
       "5             67.0   Improved                 1966      232000.0  \n",
       "6             67.0   Improved                 1966      235000.0  \n",
       "7             67.0   Improved                 1966      226000.0  \n",
       "8             67.0   Improved                 1966      215000.0  \n",
       "9             67.0   Improved                 1966      218000.0  \n",
       "10            67.0   Improved                 1966      220000.0  \n",
       "11            67.0   Improved                 1966      220000.0  \n",
       "12            67.0   Improved                 1966      210000.0  \n",
       "13            67.0   Improved                 1966      228000.0  \n",
       "14            67.0   Improved                 1966      230000.0  \n",
       "15            67.0   Improved                 1966      315000.0  \n",
       "16            67.0   Improved                 1966      311000.0  \n",
       "17            67.0   Improved                 1966      310000.0  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# performing the result (Boolean) of the conditional statement to select rows that meet the criterion\n",
    "# this is also known as filtering\n",
    "df[df['town'] == 'JURONG EAST'] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-10</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>200000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2017-11</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>232000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2018-01</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>38</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>235000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2018-06</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>226000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2018-09</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>215000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2019-07</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>39</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>218000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2019-09</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>39</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>220000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2020-01</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>220000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2020-03</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>38</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>210000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2020-08</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>39</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>228000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2020-12</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>230000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Tranc_YearMonth         town flat_type block    street_name storey_range  \\\n",
       "4          2017-10  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "5          2017-11  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "6          2018-01  JURONG EAST    3 ROOM    38  TEBAN GDNS RD     01 TO 03   \n",
       "7          2018-06  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "8          2018-09  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "9          2019-07  JURONG EAST    3 ROOM    39  TEBAN GDNS RD     01 TO 03   \n",
       "10         2019-09  JURONG EAST    3 ROOM    39  TEBAN GDNS RD     01 TO 03   \n",
       "11         2020-01  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "12         2020-03  JURONG EAST    3 ROOM    38  TEBAN GDNS RD     04 TO 06   \n",
       "13         2020-08  JURONG EAST    3 ROOM    39  TEBAN GDNS RD     04 TO 06   \n",
       "14         2020-12  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "\n",
       "    floor_area_sqm flat_model  lease_commence_date  resale_price  \n",
       "4             67.0   Improved                 1966      200000.0  \n",
       "5             67.0   Improved                 1966      232000.0  \n",
       "6             67.0   Improved                 1966      235000.0  \n",
       "7             67.0   Improved                 1966      226000.0  \n",
       "8             67.0   Improved                 1966      215000.0  \n",
       "9             67.0   Improved                 1966      218000.0  \n",
       "10            67.0   Improved                 1966      220000.0  \n",
       "11            67.0   Improved                 1966      220000.0  \n",
       "12            67.0   Improved                 1966      210000.0  \n",
       "13            67.0   Improved                 1966      228000.0  \n",
       "14            67.0   Improved                 1966      230000.0  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Select rows based on multiple criteria, by joining then usng & and | (logical operators)\n",
    "# Note that it's compulsory to have the round blacket () for each criterion and must use the & and | (not AND and OR operators)\n",
    "df[(df['town'] == 'JURONG EAST') & (df['resale_price'] < 250000)] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>39</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>260000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-08</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>289000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2016-11</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>250000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>250000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-10</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>200000.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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14389</th>\n",
       "      <td>2021-03</td>\n",
       "      <td>JURONG WEST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>209</td>\n",
       "      <td>BOON LAY PL</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>65.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1976</td>\n",
       "      <td>248000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14390</th>\n",
       "      <td>2021-03</td>\n",
       "      <td>JURONG WEST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>209</td>\n",
       "      <td>BOON LAY PL</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>65.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1976</td>\n",
       "      <td>245000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14391</th>\n",
       "      <td>2021-03</td>\n",
       "      <td>JURONG WEST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>211</td>\n",
       "      <td>BOON LAY PL</td>\n",
       "      <td>10 TO 12</td>\n",
       "      <td>65.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1976</td>\n",
       "      <td>232000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14413</th>\n",
       "      <td>2021-03</td>\n",
       "      <td>WOODLANDS</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>6</td>\n",
       "      <td>MARSILING DR</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>65.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1976</td>\n",
       "      <td>228888.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14439</th>\n",
       "      <td>2021-04</td>\n",
       "      <td>WOODLANDS</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>13</td>\n",
       "      <td>MARSILING LANE</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>76.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1976</td>\n",
       "      <td>240000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2229 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Tranc_YearMonth         town flat_type block     street_name  \\\n",
       "0             2015-03  JURONG EAST    3 ROOM    39   TEBAN GDNS RD   \n",
       "1             2015-08  JURONG EAST    3 ROOM    37   TEBAN GDNS RD   \n",
       "2             2016-11  JURONG EAST    3 ROOM    37   TEBAN GDNS RD   \n",
       "3             2017-01  JURONG EAST    3 ROOM    37   TEBAN GDNS RD   \n",
       "4             2017-10  JURONG EAST    3 ROOM    37   TEBAN GDNS RD   \n",
       "...               ...          ...       ...   ...             ...   \n",
       "14389         2021-03  JURONG WEST    3 ROOM   209     BOON LAY PL   \n",
       "14390         2021-03  JURONG WEST    3 ROOM   209     BOON LAY PL   \n",
       "14391         2021-03  JURONG WEST    3 ROOM   211     BOON LAY PL   \n",
       "14413         2021-03    WOODLANDS    3 ROOM     6    MARSILING DR   \n",
       "14439         2021-04    WOODLANDS    3 ROOM    13  MARSILING LANE   \n",
       "\n",
       "      storey_range  floor_area_sqm flat_model  lease_commence_date  \\\n",
       "0         01 TO 03            67.0   Improved                 1966   \n",
       "1         04 TO 06            67.0   Improved                 1966   \n",
       "2         04 TO 06            67.0   Improved                 1966   \n",
       "3         04 TO 06            67.0   Improved                 1966   \n",
       "4         01 TO 03            67.0   Improved                 1966   \n",
       "...            ...             ...        ...                  ...   \n",
       "14389     01 TO 03            65.0   Improved                 1976   \n",
       "14390     01 TO 03            65.0   Improved                 1976   \n",
       "14391     10 TO 12            65.0   Improved                 1976   \n",
       "14413     04 TO 06            65.0   Improved                 1976   \n",
       "14439     07 TO 09            76.0   Improved                 1976   \n",
       "\n",
       "       resale_price  \n",
       "0          260000.0  \n",
       "1          289000.0  \n",
       "2          250000.0  \n",
       "3          250000.0  \n",
       "4          200000.0  \n",
       "...             ...  \n",
       "14389      248000.0  \n",
       "14390      245000.0  \n",
       "14391      232000.0  \n",
       "14413      228888.0  \n",
       "14439      240000.0  \n",
       "\n",
       "[2229 rows x 10 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[(df['town'] == 'JURONG EAST') | (df['resale_price'] < 250000)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>GEYLANG</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>20</td>\n",
       "      <td>BALAM RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>60.3</td>\n",
       "      <td>Standard</td>\n",
       "      <td>1967</td>\n",
       "      <td>275000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>GEYLANG</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>23</td>\n",
       "      <td>BALAM RD</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>60.3</td>\n",
       "      <td>Standard</td>\n",
       "      <td>1967</td>\n",
       "      <td>282000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>QUEENSTOWN</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>83</td>\n",
       "      <td>C'WEALTH CL</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>60.0</td>\n",
       "      <td>Standard</td>\n",
       "      <td>1967</td>\n",
       "      <td>310000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>QUEENSTOWN</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>95</td>\n",
       "      <td>C'WEALTH DR</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>68.0</td>\n",
       "      <td>Standard</td>\n",
       "      <td>1967</td>\n",
       "      <td>335000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>QUEENSTOWN</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>93</td>\n",
       "      <td>C'WEALTH DR</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>60.0</td>\n",
       "      <td>Standard</td>\n",
       "      <td>1967</td>\n",
       "      <td>350000.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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14995</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>JURONG WEST</td>\n",
       "      <td>5 ROOM</td>\n",
       "      <td>206</td>\n",
       "      <td>BOON LAY DR</td>\n",
       "      <td>19 TO 21</td>\n",
       "      <td>120.0</td>\n",
       "      <td>Standard</td>\n",
       "      <td>1976</td>\n",
       "      <td>495000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14996</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>JURONG WEST</td>\n",
       "      <td>5 ROOM</td>\n",
       "      <td>211</td>\n",
       "      <td>BOON LAY PL</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>130.0</td>\n",
       "      <td>Adjoined flat</td>\n",
       "      <td>1976</td>\n",
       "      <td>530000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14997</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>MARINE PARADE</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>67</td>\n",
       "      <td>MARINE DR</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>65.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1976</td>\n",
       "      <td>400000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14998</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>MARINE PARADE</td>\n",
       "      <td>4 ROOM</td>\n",
       "      <td>76</td>\n",
       "      <td>MARINE DR</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>82.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1976</td>\n",
       "      <td>540000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14999</th>\n",
       "      <td>2013-06</td>\n",
       "      <td>MARINE PARADE</td>\n",
       "      <td>4 ROOM</td>\n",
       "      <td>62</td>\n",
       "      <td>MARINE DR</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>87.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1976</td>\n",
       "      <td>611888.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>14982 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Tranc_YearMonth           town flat_type block  street_name  \\\n",
       "18            2015-01        GEYLANG    3 ROOM    20     BALAM RD   \n",
       "19            2015-01        GEYLANG    3 ROOM    23     BALAM RD   \n",
       "20            2015-01     QUEENSTOWN    3 ROOM    83  C'WEALTH CL   \n",
       "21            2015-01     QUEENSTOWN    3 ROOM    95  C'WEALTH DR   \n",
       "22            2015-01     QUEENSTOWN    3 ROOM    93  C'WEALTH DR   \n",
       "...               ...            ...       ...   ...          ...   \n",
       "14995         2013-06    JURONG WEST    5 ROOM   206  BOON LAY DR   \n",
       "14996         2013-06    JURONG WEST    5 ROOM   211  BOON LAY PL   \n",
       "14997         2013-06  MARINE PARADE    3 ROOM    67    MARINE DR   \n",
       "14998         2013-06  MARINE PARADE    4 ROOM    76    MARINE DR   \n",
       "14999         2013-06  MARINE PARADE    4 ROOM    62    MARINE DR   \n",
       "\n",
       "      storey_range  floor_area_sqm     flat_model  lease_commence_date  \\\n",
       "18        04 TO 06            60.3       Standard                 1967   \n",
       "19        07 TO 09            60.3       Standard                 1967   \n",
       "20        04 TO 06            60.0       Standard                 1967   \n",
       "21        04 TO 06            68.0       Standard                 1967   \n",
       "22        04 TO 06            60.0       Standard                 1967   \n",
       "...            ...             ...            ...                  ...   \n",
       "14995     19 TO 21           120.0       Standard                 1976   \n",
       "14996     07 TO 09           130.0  Adjoined flat                 1976   \n",
       "14997     01 TO 03            65.0       Improved                 1976   \n",
       "14998     01 TO 03            82.0       Improved                 1976   \n",
       "14999     04 TO 06            87.0       Improved                 1976   \n",
       "\n",
       "       resale_price  \n",
       "18         275000.0  \n",
       "19         282000.0  \n",
       "20         310000.0  \n",
       "21         335000.0  \n",
       "22         350000.0  \n",
       "...             ...  \n",
       "14995      495000.0  \n",
       "14996      530000.0  \n",
       "14997      400000.0  \n",
       "14998      540000.0  \n",
       "14999      611888.0  \n",
       "\n",
       "[14982 rows x 10 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[(df['town'] != 'JURONG EAST')] "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Doing calculations using columns in a DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "      <th>resale_price_in_thousands</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-03</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>39</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>260000.0</td>\n",
       "      <td>test</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-08</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>289000.0</td>\n",
       "      <td>test</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2016-11</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>250000.0</td>\n",
       "      <td>test</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>250000.0</td>\n",
       "      <td>test</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-10</td>\n",
       "      <td>JURONG EAST</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>37</td>\n",
       "      <td>TEBAN GDNS RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1966</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>test</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Tranc_YearMonth         town flat_type block    street_name storey_range  \\\n",
       "0         2015-03  JURONG EAST    3 ROOM    39  TEBAN GDNS RD     01 TO 03   \n",
       "1         2015-08  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "2         2016-11  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "3         2017-01  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     04 TO 06   \n",
       "4         2017-10  JURONG EAST    3 ROOM    37  TEBAN GDNS RD     01 TO 03   \n",
       "\n",
       "   floor_area_sqm flat_model  lease_commence_date  resale_price  \\\n",
       "0            67.0   Improved                 1966      260000.0   \n",
       "1            67.0   Improved                 1966      289000.0   \n",
       "2            67.0   Improved                 1966      250000.0   \n",
       "3            67.0   Improved                 1966      250000.0   \n",
       "4            67.0   Improved                 1966      200000.0   \n",
       "\n",
       "  resale_price_in_thousands  \n",
       "0                      test  \n",
       "1                      test  \n",
       "2                      test  \n",
       "3                      test  \n",
       "4                      test  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# first, understand how to create a new column\n",
    "df['resale_price_in_thousands'] = 'test'\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        260.000\n",
       "1        289.000\n",
       "2        250.000\n",
       "3        250.000\n",
       "4        200.000\n",
       "          ...   \n",
       "14995    495.000\n",
       "14996    530.000\n",
       "14997    400.000\n",
       "14998    540.000\n",
       "14999    611.888\n",
       "Name: resale_price, Length: 15000, dtype: float64"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['resale_price'] / 1000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['resale_price_in_thousands'] = df['resale_price'] / 1000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Now try using multiple columns \n",
    "df['price_per_sqm'] = df['resale_price'] / df['floor_area_sqm']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Removing a column \n",
    "df = df.drop('resale_price_in_thousands', axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Using Numpy functions with a DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "355261.5643086667"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# using the function from Numpy\n",
    "np.mean(df['resale_price'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "355261.5643086667"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# using the built-in numpy functions from the DataFrame object\n",
    "# encouraged way, but not all functions may available via this way\n",
    "df['resale_price'].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>resale_price</th>\n",
       "      <th>price_per_sqm</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>260000.0</td>\n",
       "      <td>3880.597015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>289000.0</td>\n",
       "      <td>4313.432836</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>250000.0</td>\n",
       "      <td>3731.343284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>250000.0</td>\n",
       "      <td>3731.343284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>200000.0</td>\n",
       "      <td>2985.074627</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14995</th>\n",
       "      <td>495000.0</td>\n",
       "      <td>4125.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14996</th>\n",
       "      <td>530000.0</td>\n",
       "      <td>4076.923077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14997</th>\n",
       "      <td>400000.0</td>\n",
       "      <td>6153.846154</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14998</th>\n",
       "      <td>540000.0</td>\n",
       "      <td>6585.365854</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14999</th>\n",
       "      <td>611888.0</td>\n",
       "      <td>7033.195402</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>15000 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       resale_price  price_per_sqm\n",
       "0          260000.0    3880.597015\n",
       "1          289000.0    4313.432836\n",
       "2          250000.0    3731.343284\n",
       "3          250000.0    3731.343284\n",
       "4          200000.0    2985.074627\n",
       "...             ...            ...\n",
       "14995      495000.0    4125.000000\n",
       "14996      530000.0    4076.923077\n",
       "14997      400000.0    6153.846154\n",
       "14998      540000.0    6585.365854\n",
       "14999      611888.0    7033.195402\n",
       "\n",
       "[15000 rows x 2 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# creating a subset of the dataframe, selected columns only\n",
    "df_sub = df[['resale_price', 'price_per_sqm']]\n",
    "df_sub"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        131940.298507\n",
       "1        146656.716418\n",
       "2        126865.671642\n",
       "3        126865.671642\n",
       "4        101492.537313\n",
       "             ...      \n",
       "14995    249562.500000\n",
       "14996    267038.461538\n",
       "14997    203076.923077\n",
       "14998    273292.682927\n",
       "14999    309460.597701\n",
       "Length: 15000, dtype: float64"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# applying the mean() method to the columns \n",
    "# that is, to average the values across columns\n",
    "df_sub.mean(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "resale_price     355261.564309\n",
       "price_per_sqm      5056.182315\n",
       "dtype: float64"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# applying the mean() method to rows\n",
    "# that is, to average the values across rows\n",
    "df_sub.mean(axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "## Extra: Getting data from websites (Intenet required)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Have a look at the website to see how it looks visually\n",
    "tables = pd.read_html('https://en.wikipedia.org/wiki/List_of_unicorn_startup_companies')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Valuation(US$ billions)</th>\n",
       "      <th>Valuation date</th>\n",
       "      <th>Industry</th>\n",
       "      <th>Country/countries</th>\n",
       "      <th>Founder(s)</th>\n",
       "      <th>Unnamed: 6</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ByteDance</td>\n",
       "      <td>400</td>\n",
       "      <td>April 2021[12]</td>\n",
       "      <td>Internet</td>\n",
       "      <td>China</td>\n",
       "      <td>Zhang Yiming, Liang Rubo</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Shein</td>\n",
       "      <td>100</td>\n",
       "      <td>April 2022[13]</td>\n",
       "      <td>E-commerce</td>\n",
       "      <td>China</td>\n",
       "      <td>Chris Xu</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>SpaceX</td>\n",
       "      <td>100</td>\n",
       "      <td>October 2021[14]</td>\n",
       "      <td>Aerospace</td>\n",
       "      <td>US</td>\n",
       "      <td>Elon Musk</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Stripe</td>\n",
       "      <td>95</td>\n",
       "      <td>March 2021[15]</td>\n",
       "      <td>Financial services</td>\n",
       "      <td>US / Ireland</td>\n",
       "      <td>Patrick and John Collison</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Klarna</td>\n",
       "      <td>45.6</td>\n",
       "      <td>June 2021[16]</td>\n",
       "      <td>Financial technology</td>\n",
       "      <td>Sweden</td>\n",
       "      <td>Sebastian Siemiatkowski, Niklas Adalberth, Vic...</td>\n",
       "      <td>NaN</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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>630</th>\n",
       "      <td>Zuoyebang</td>\n",
       "      <td>1+</td>\n",
       "      <td>July 2018[129]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>China</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>631</th>\n",
       "      <td>Einride</td>\n",
       "      <td>1.44</td>\n",
       "      <td>April 2022[574]</td>\n",
       "      <td>Technology</td>\n",
       "      <td>Sweden</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>632</th>\n",
       "      <td>Voi</td>\n",
       "      <td>1+</td>\n",
       "      <td>April 2022[575]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Sweden</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>633</th>\n",
       "      <td>Bitkub</td>\n",
       "      <td>1+</td>\n",
       "      <td>November 2021[576][577]</td>\n",
       "      <td>Financial technology</td>\n",
       "      <td>Thailand</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>634</th>\n",
       "      <td>Nagad</td>\n",
       "      <td>1+</td>\n",
       "      <td>April 2022[578]</td>\n",
       "      <td>Financial services</td>\n",
       "      <td>Bangladesh</td>\n",
       "      <td>Rahel Ahmed</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>635 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       Company Valuation(US$ billions)           Valuation date  \\\n",
       "0    ByteDance                     400           April 2021[12]   \n",
       "1        Shein                     100           April 2022[13]   \n",
       "2       SpaceX                     100         October 2021[14]   \n",
       "3       Stripe                      95           March 2021[15]   \n",
       "4       Klarna                    45.6            June 2021[16]   \n",
       "..         ...                     ...                      ...   \n",
       "630  Zuoyebang                      1+           July 2018[129]   \n",
       "631    Einride                    1.44          April 2022[574]   \n",
       "632        Voi                      1+          April 2022[575]   \n",
       "633     Bitkub                      1+  November 2021[576][577]   \n",
       "634      Nagad                      1+          April 2022[578]   \n",
       "\n",
       "                 Industry Country/countries  \\\n",
       "0                Internet             China   \n",
       "1              E-commerce             China   \n",
       "2               Aerospace                US   \n",
       "3      Financial services      US / Ireland   \n",
       "4    Financial technology            Sweden   \n",
       "..                    ...               ...   \n",
       "630                   NaN             China   \n",
       "631            Technology            Sweden   \n",
       "632                   NaN            Sweden   \n",
       "633  Financial technology          Thailand   \n",
       "634    Financial services        Bangladesh   \n",
       "\n",
       "                                            Founder(s)  Unnamed: 6  \n",
       "0                             Zhang Yiming, Liang Rubo         NaN  \n",
       "1                                             Chris Xu         NaN  \n",
       "2                                            Elon Musk         NaN  \n",
       "3                            Patrick and John Collison         NaN  \n",
       "4    Sebastian Siemiatkowski, Niklas Adalberth, Vic...         NaN  \n",
       "..                                                 ...         ...  \n",
       "630                                                NaN         NaN  \n",
       "631                                                NaN         NaN  \n",
       "632                                                NaN         NaN  \n",
       "633                                                NaN         NaN  \n",
       "634                                        Rahel Ahmed         NaN  \n",
       "\n",
       "[635 rows x 7 columns]"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get the 4th DataFrames that being captured\n",
    "tables[3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# !! Your Turn !!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Replace the code marked as <..> COMPLETELY with your own.\n",
    "For example:\n",
    "length = <..> will be replaced by length = 10"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 1 \n",
    "1) Read hdb_resale_full_raw.csv into pandas and named it <b>df_hdb</b> <br/>\n",
    "2) print out the shape of <b>df_hdb</b>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(185968, 10)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd \n",
    "\n",
    "df_hdb = pd.read_csv('data/0_raw_data/hdb_resale_full_raw.csv')\n",
    "\n",
    "df_hdb.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "3) Find out how many non-null records are there for each column\\\n",
    "hint: using the methods that we have learnt from codes above (or from this week's content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 185968 entries, 0 to 185967\n",
      "Data columns (total 10 columns):\n",
      " #   Column               Non-Null Count   Dtype  \n",
      "---  ------               --------------   -----  \n",
      " 0   Tranc_YearMonth      185968 non-null  object \n",
      " 1   town                 185968 non-null  object \n",
      " 2   flat_type            185968 non-null  object \n",
      " 3   block                185968 non-null  object \n",
      " 4   street_name          185968 non-null  object \n",
      " 5   storey_range         185968 non-null  object \n",
      " 6   floor_area_sqm       185968 non-null  float64\n",
      " 7   flat_model           185968 non-null  object \n",
      " 8   lease_commence_date  185968 non-null  int64  \n",
      " 9   resale_price         185968 non-null  float64\n",
      "dtypes: float64(2), int64(1), object(7)\n",
      "memory usage: 14.2+ MB\n"
     ]
    }
   ],
   "source": [
    "df_hdb.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 2\n",
    "1) list out the unique values for <b>flat_type</b> <br/>\n",
    "2) print out the number of records for each of the <b>town</b> <br/>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['3 ROOM', '4 ROOM', '5 ROOM', '2 ROOM', 'EXECUTIVE', '1 ROOM',\n",
       "       'MULTI-GENERATION'], dtype=object)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_hdb ['flat_type'].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "JURONG WEST        14152\n",
       "WOODLANDS          13944\n",
       "SENGKANG           13692\n",
       "TAMPINES           12939\n",
       "YISHUN             12301\n",
       "BEDOK              11128\n",
       "PUNGGOL             9615\n",
       "HOUGANG             9258\n",
       "ANG MO KIO          8661\n",
       "CHOA CHU KANG       7856\n",
       "BUKIT MERAH         7227\n",
       "BUKIT PANJANG       7029\n",
       "BUKIT BATOK         7005\n",
       "TOA PAYOH           5967\n",
       "PASIR RIS           5950\n",
       "KALLANG/WHAMPOA     5398\n",
       "QUEENSTOWN          5113\n",
       "GEYLANG             4919\n",
       "SEMBAWANG           4572\n",
       "CLEMENTI            4445\n",
       "JURONG EAST         4209\n",
       "SERANGOON           3872\n",
       "BISHAN              3537\n",
       "CENTRAL AREA        1522\n",
       "MARINE PARADE       1203\n",
       "BUKIT TIMAH          454\n",
       "Name: town, dtype: int64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_hdb ['town'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1) Select the all the records from **Ang Mo Kio**.\\\n",
    "No need to assign the output to any variable, just show the filtered dataframe on the notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>174</td>\n",
       "      <td>ANG MO KIO AVE 4</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>60.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1986</td>\n",
       "      <td>255000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>541</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1981</td>\n",
       "      <td>275000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>163</td>\n",
       "      <td>ANG MO KIO AVE 4</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>69.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1980</td>\n",
       "      <td>285000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>446</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1979</td>\n",
       "      <td>290000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>557</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1980</td>\n",
       "      <td>290000.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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181943</th>\n",
       "      <td>2014-12</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>5 ROOM</td>\n",
       "      <td>642</td>\n",
       "      <td>ANG MO KIO AVE 5</td>\n",
       "      <td>13 TO 15</td>\n",
       "      <td>121.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1980</td>\n",
       "      <td>618000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181944</th>\n",
       "      <td>2014-12</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>5 ROOM</td>\n",
       "      <td>700B</td>\n",
       "      <td>ANG MO KIO AVE 6</td>\n",
       "      <td>16 TO 18</td>\n",
       "      <td>111.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>2003</td>\n",
       "      <td>808000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181945</th>\n",
       "      <td>2014-12</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>5 ROOM</td>\n",
       "      <td>596B</td>\n",
       "      <td>ANG MO KIO ST 52</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>110.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>2002</td>\n",
       "      <td>745000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181946</th>\n",
       "      <td>2014-12</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>EXECUTIVE</td>\n",
       "      <td>611</td>\n",
       "      <td>ANG MO KIO AVE 5</td>\n",
       "      <td>10 TO 12</td>\n",
       "      <td>178.0</td>\n",
       "      <td>Adjoined flat</td>\n",
       "      <td>1980</td>\n",
       "      <td>938000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184985</th>\n",
       "      <td>2021-02</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>339</td>\n",
       "      <td>ANG MO KIO AVE 1</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>66.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1981</td>\n",
       "      <td>282000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8661 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       Tranc_YearMonth        town  flat_type block        street_name  \\\n",
       "0              2015-01  ANG MO KIO     3 ROOM   174   ANG MO KIO AVE 4   \n",
       "1              2015-01  ANG MO KIO     3 ROOM   541  ANG MO KIO AVE 10   \n",
       "2              2015-01  ANG MO KIO     3 ROOM   163   ANG MO KIO AVE 4   \n",
       "3              2015-01  ANG MO KIO     3 ROOM   446  ANG MO KIO AVE 10   \n",
       "4              2015-01  ANG MO KIO     3 ROOM   557  ANG MO KIO AVE 10   \n",
       "...                ...         ...        ...   ...                ...   \n",
       "181943         2014-12  ANG MO KIO     5 ROOM   642   ANG MO KIO AVE 5   \n",
       "181944         2014-12  ANG MO KIO     5 ROOM  700B   ANG MO KIO AVE 6   \n",
       "181945         2014-12  ANG MO KIO     5 ROOM  596B   ANG MO KIO ST 52   \n",
       "181946         2014-12  ANG MO KIO  EXECUTIVE   611   ANG MO KIO AVE 5   \n",
       "184985         2021-02  ANG MO KIO     3 ROOM   339   ANG MO KIO AVE 1   \n",
       "\n",
       "       storey_range  floor_area_sqm      flat_model  lease_commence_date  \\\n",
       "0          07 TO 09            60.0        Improved                 1986   \n",
       "1          01 TO 03            68.0  New Generation                 1981   \n",
       "2          01 TO 03            69.0  New Generation                 1980   \n",
       "3          01 TO 03            68.0  New Generation                 1979   \n",
       "4          07 TO 09            68.0  New Generation                 1980   \n",
       "...             ...             ...             ...                  ...   \n",
       "181943     13 TO 15           121.0        Improved                 1980   \n",
       "181944     16 TO 18           111.0        Improved                 2003   \n",
       "181945     07 TO 09           110.0        Improved                 2002   \n",
       "181946     10 TO 12           178.0   Adjoined flat                 1980   \n",
       "184985     01 TO 03            66.0        Improved                 1981   \n",
       "\n",
       "        resale_price  \n",
       "0           255000.0  \n",
       "1           275000.0  \n",
       "2           285000.0  \n",
       "3           290000.0  \n",
       "4           290000.0  \n",
       "...              ...  \n",
       "181943      618000.0  \n",
       "181944      808000.0  \n",
       "181945      745000.0  \n",
       "181946      938000.0  \n",
       "184985      282000.0  \n",
       "\n",
       "[8661 rows x 10 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_hdb[df_hdb['town'] == 'ANG MO KIO']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2) Select the all the records of which the lease commence date is before 1980.\\\n",
    "No need to assign the output to any variable, just show the filtered dataframe on the notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>174</td>\n",
       "      <td>ANG MO KIO AVE 4</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>60.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1986</td>\n",
       "      <td>255000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>541</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1981</td>\n",
       "      <td>275000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>333</td>\n",
       "      <td>ANG MO KIO AVE 1</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1981</td>\n",
       "      <td>293000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>564</td>\n",
       "      <td>ANG MO KIO AVE 3</td>\n",
       "      <td>13 TO 15</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1985</td>\n",
       "      <td>307500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>156</td>\n",
       "      <td>ANG MO KIO AVE 4</td>\n",
       "      <td>10 TO 12</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1981</td>\n",
       "      <td>312000.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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185961</th>\n",
       "      <td>2014-11</td>\n",
       "      <td>KALLANG/WHAMPOA</td>\n",
       "      <td>4 ROOM</td>\n",
       "      <td>4B</td>\n",
       "      <td>ST. GEORGE'S LANE</td>\n",
       "      <td>13 TO 15</td>\n",
       "      <td>105.0</td>\n",
       "      <td>Model A</td>\n",
       "      <td>1996</td>\n",
       "      <td>570000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185962</th>\n",
       "      <td>2014-12</td>\n",
       "      <td>KALLANG/WHAMPOA</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>5</td>\n",
       "      <td>ST. GEORGE'S LANE</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1981</td>\n",
       "      <td>330000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185964</th>\n",
       "      <td>2014-12</td>\n",
       "      <td>KALLANG/WHAMPOA</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>14</td>\n",
       "      <td>ST. GEORGE'S RD</td>\n",
       "      <td>10 TO 12</td>\n",
       "      <td>67.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1984</td>\n",
       "      <td>364000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185965</th>\n",
       "      <td>2014-12</td>\n",
       "      <td>KALLANG/WHAMPOA</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>20</td>\n",
       "      <td>ST. GEORGE'S RD</td>\n",
       "      <td>10 TO 12</td>\n",
       "      <td>67.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1984</td>\n",
       "      <td>358000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185967</th>\n",
       "      <td>2014-12</td>\n",
       "      <td>SENGKANG</td>\n",
       "      <td>4 ROOM</td>\n",
       "      <td>238</td>\n",
       "      <td>COMPASSVALE WALK</td>\n",
       "      <td>04 TO 06</td>\n",
       "      <td>101.0</td>\n",
       "      <td>Model A</td>\n",
       "      <td>1999</td>\n",
       "      <td>433000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>151687 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       Tranc_YearMonth             town flat_type block        street_name  \\\n",
       "0              2015-01       ANG MO KIO    3 ROOM   174   ANG MO KIO AVE 4   \n",
       "1              2015-01       ANG MO KIO    3 ROOM   541  ANG MO KIO AVE 10   \n",
       "7              2015-01       ANG MO KIO    3 ROOM   333   ANG MO KIO AVE 1   \n",
       "9              2015-01       ANG MO KIO    3 ROOM   564   ANG MO KIO AVE 3   \n",
       "12             2015-01       ANG MO KIO    3 ROOM   156   ANG MO KIO AVE 4   \n",
       "...                ...              ...       ...   ...                ...   \n",
       "185961         2014-11  KALLANG/WHAMPOA    4 ROOM    4B  ST. GEORGE'S LANE   \n",
       "185962         2014-12  KALLANG/WHAMPOA    3 ROOM     5  ST. GEORGE'S LANE   \n",
       "185964         2014-12  KALLANG/WHAMPOA    3 ROOM    14    ST. GEORGE'S RD   \n",
       "185965         2014-12  KALLANG/WHAMPOA    3 ROOM    20    ST. GEORGE'S RD   \n",
       "185967         2014-12         SENGKANG    4 ROOM   238   COMPASSVALE WALK   \n",
       "\n",
       "       storey_range  floor_area_sqm      flat_model  lease_commence_date  \\\n",
       "0          07 TO 09            60.0        Improved                 1986   \n",
       "1          01 TO 03            68.0  New Generation                 1981   \n",
       "7          01 TO 03            68.0  New Generation                 1981   \n",
       "9          13 TO 15            68.0  New Generation                 1985   \n",
       "12         10 TO 12            68.0  New Generation                 1981   \n",
       "...             ...             ...             ...                  ...   \n",
       "185961     13 TO 15           105.0         Model A                 1996   \n",
       "185962     01 TO 03            68.0  New Generation                 1981   \n",
       "185964     10 TO 12            67.0  New Generation                 1984   \n",
       "185965     10 TO 12            67.0  New Generation                 1984   \n",
       "185967     04 TO 06           101.0         Model A                 1999   \n",
       "\n",
       "        resale_price  \n",
       "0           255000.0  \n",
       "1           275000.0  \n",
       "7           293000.0  \n",
       "9           307500.0  \n",
       "12          312000.0  \n",
       "...              ...  \n",
       "185961      570000.0  \n",
       "185962      330000.0  \n",
       "185964      364000.0  \n",
       "185965      358000.0  \n",
       "185967      433000.0  \n",
       "\n",
       "[151687 rows x 10 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_hdb[df_hdb['lease_commence_date'] > 1980]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Question 4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Select resale transactions for flats in **Bedok** and under $300,000 in resale price\\\n",
    "No need to assign the output to any variable, just show the filtered dataframe on the notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>2 ROOM</td>\n",
       "      <td>620</td>\n",
       "      <td>BEDOK RESERVOIR RD</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>45.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1986</td>\n",
       "      <td>246000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>2 ROOM</td>\n",
       "      <td>38</td>\n",
       "      <td>BEDOK STH RD</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>44.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1978</td>\n",
       "      <td>255000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>504</td>\n",
       "      <td>BEDOK NTH ST 3</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>59.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1978</td>\n",
       "      <td>270000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>545</td>\n",
       "      <td>BEDOK NTH ST 3</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1980</td>\n",
       "      <td>280000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>546</td>\n",
       "      <td>BEDOK NTH ST 3</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1980</td>\n",
       "      <td>280000.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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181973</th>\n",
       "      <td>2014-12</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>620</td>\n",
       "      <td>BEDOK RESERVOIR RD</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>61.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1986</td>\n",
       "      <td>285000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181988</th>\n",
       "      <td>2014-12</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>26</td>\n",
       "      <td>NEW UPP CHANGI RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>66.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1974</td>\n",
       "      <td>270000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>183445</th>\n",
       "      <td>2020-03</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>2 ROOM</td>\n",
       "      <td>807B</td>\n",
       "      <td>CHAI CHEE RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>47.0</td>\n",
       "      <td>Model A</td>\n",
       "      <td>2016</td>\n",
       "      <td>240000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184026</th>\n",
       "      <td>2020-10</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>2 ROOM</td>\n",
       "      <td>807B</td>\n",
       "      <td>CHAI CHEE RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>47.0</td>\n",
       "      <td>Model A</td>\n",
       "      <td>2016</td>\n",
       "      <td>260000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184724</th>\n",
       "      <td>2021-01</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>2 ROOM</td>\n",
       "      <td>808B</td>\n",
       "      <td>CHAI CHEE RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>47.0</td>\n",
       "      <td>Model A</td>\n",
       "      <td>2016</td>\n",
       "      <td>275000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2027 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       Tranc_YearMonth   town flat_type block         street_name  \\\n",
       "59             2015-01  BEDOK    2 ROOM   620  BEDOK RESERVOIR RD   \n",
       "60             2015-01  BEDOK    2 ROOM    38        BEDOK STH RD   \n",
       "61             2015-01  BEDOK    3 ROOM   504      BEDOK NTH ST 3   \n",
       "62             2015-01  BEDOK    3 ROOM   545      BEDOK NTH ST 3   \n",
       "63             2015-01  BEDOK    3 ROOM   546      BEDOK NTH ST 3   \n",
       "...                ...    ...       ...   ...                 ...   \n",
       "181973         2014-12  BEDOK    3 ROOM   620  BEDOK RESERVOIR RD   \n",
       "181988         2014-12  BEDOK    3 ROOM    26   NEW UPP CHANGI RD   \n",
       "183445         2020-03  BEDOK    2 ROOM  807B        CHAI CHEE RD   \n",
       "184026         2020-10  BEDOK    2 ROOM  807B        CHAI CHEE RD   \n",
       "184724         2021-01  BEDOK    2 ROOM  808B        CHAI CHEE RD   \n",
       "\n",
       "       storey_range  floor_area_sqm      flat_model  lease_commence_date  \\\n",
       "59         07 TO 09            45.0        Improved                 1986   \n",
       "60         07 TO 09            44.0        Improved                 1978   \n",
       "61         07 TO 09            59.0        Improved                 1978   \n",
       "62         07 TO 09            68.0  New Generation                 1980   \n",
       "63         01 TO 03            68.0  New Generation                 1980   \n",
       "...             ...             ...             ...                  ...   \n",
       "181973     07 TO 09            61.0        Improved                 1986   \n",
       "181988     01 TO 03            66.0        Improved                 1974   \n",
       "183445     01 TO 03            47.0         Model A                 2016   \n",
       "184026     01 TO 03            47.0         Model A                 2016   \n",
       "184724     01 TO 03            47.0         Model A                 2016   \n",
       "\n",
       "        resale_price  \n",
       "59          246000.0  \n",
       "60          255000.0  \n",
       "61          270000.0  \n",
       "62          280000.0  \n",
       "63          280000.0  \n",
       "...              ...  \n",
       "181973      285000.0  \n",
       "181988      270000.0  \n",
       "183445      240000.0  \n",
       "184026      260000.0  \n",
       "184724      275000.0  \n",
       "\n",
       "[2027 rows x 10 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_hdb[(df_hdb['resale_price'] < 300000) & (df_hdb['town'] == 'BEDOK')]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Select resale transactions for flats in Bedok and Ang Mo Kio, which the resale price is between \\$250k and 500K \\\n",
    "No need to assign the output to any variable, just show the filtered dataframe on the notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>174</td>\n",
       "      <td>ANG MO KIO AVE 4</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>60.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1986</td>\n",
       "      <td>255000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>541</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1981</td>\n",
       "      <td>275000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>163</td>\n",
       "      <td>ANG MO KIO AVE 4</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>69.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1980</td>\n",
       "      <td>285000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>446</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1979</td>\n",
       "      <td>290000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>557</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1980</td>\n",
       "      <td>290000.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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184988</th>\n",
       "      <td>2021-02</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>807A</td>\n",
       "      <td>CHAI CHEE RD</td>\n",
       "      <td>13 TO 15</td>\n",
       "      <td>68.0</td>\n",
       "      <td>Model A</td>\n",
       "      <td>2016</td>\n",
       "      <td>480000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184989</th>\n",
       "      <td>2021-02</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>808A</td>\n",
       "      <td>CHAI CHEE RD</td>\n",
       "      <td>10 TO 12</td>\n",
       "      <td>68.0</td>\n",
       "      <td>Model A</td>\n",
       "      <td>2016</td>\n",
       "      <td>480000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185251</th>\n",
       "      <td>2021-03</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>808B</td>\n",
       "      <td>CHAI CHEE RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>Model A</td>\n",
       "      <td>2016</td>\n",
       "      <td>425000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185579</th>\n",
       "      <td>2021-04</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>808C</td>\n",
       "      <td>CHAI CHEE RD</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>68.0</td>\n",
       "      <td>Model A</td>\n",
       "      <td>2016</td>\n",
       "      <td>475000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185580</th>\n",
       "      <td>2021-04</td>\n",
       "      <td>BEDOK</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>807C</td>\n",
       "      <td>CHAI CHEE RD</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>Model A</td>\n",
       "      <td>2016</td>\n",
       "      <td>445000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>14618 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       Tranc_YearMonth        town flat_type block        street_name  \\\n",
       "0              2015-01  ANG MO KIO    3 ROOM   174   ANG MO KIO AVE 4   \n",
       "1              2015-01  ANG MO KIO    3 ROOM   541  ANG MO KIO AVE 10   \n",
       "2              2015-01  ANG MO KIO    3 ROOM   163   ANG MO KIO AVE 4   \n",
       "3              2015-01  ANG MO KIO    3 ROOM   446  ANG MO KIO AVE 10   \n",
       "4              2015-01  ANG MO KIO    3 ROOM   557  ANG MO KIO AVE 10   \n",
       "...                ...         ...       ...   ...                ...   \n",
       "184988         2021-02       BEDOK    3 ROOM  807A       CHAI CHEE RD   \n",
       "184989         2021-02       BEDOK    3 ROOM  808A       CHAI CHEE RD   \n",
       "185251         2021-03       BEDOK    3 ROOM  808B       CHAI CHEE RD   \n",
       "185579         2021-04       BEDOK    3 ROOM  808C       CHAI CHEE RD   \n",
       "185580         2021-04       BEDOK    3 ROOM  807C       CHAI CHEE RD   \n",
       "\n",
       "       storey_range  floor_area_sqm      flat_model  lease_commence_date  \\\n",
       "0          07 TO 09            60.0        Improved                 1986   \n",
       "1          01 TO 03            68.0  New Generation                 1981   \n",
       "2          01 TO 03            69.0  New Generation                 1980   \n",
       "3          01 TO 03            68.0  New Generation                 1979   \n",
       "4          07 TO 09            68.0  New Generation                 1980   \n",
       "...             ...             ...             ...                  ...   \n",
       "184988     13 TO 15            68.0         Model A                 2016   \n",
       "184989     10 TO 12            68.0         Model A                 2016   \n",
       "185251     01 TO 03            68.0         Model A                 2016   \n",
       "185579     07 TO 09            68.0         Model A                 2016   \n",
       "185580     01 TO 03            68.0         Model A                 2016   \n",
       "\n",
       "        resale_price  \n",
       "0           255000.0  \n",
       "1           275000.0  \n",
       "2           285000.0  \n",
       "3           290000.0  \n",
       "4           290000.0  \n",
       "...              ...  \n",
       "184988      480000.0  \n",
       "184989      480000.0  \n",
       "185251      425000.0  \n",
       "185579      475000.0  \n",
       "185580      445000.0  \n",
       "\n",
       "[14618 rows x 10 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_hdb[((df_hdb['town'] == 'ANG MO KIO') | (df_hdb['town'] == 'BEDOK')) & ((df_hdb['resale_price'] >= 250000 ) & (df_hdb['resale_price'] < 500000))]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. What are the differetn **flat_model** available in the resale transactions for **4-room** flats in **bedok**.\\\n",
    "Print out each of the **flat_model** on a separat line."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['New Generation',\n",
       " 'Simplified',\n",
       " 'Improved',\n",
       " 'Model A',\n",
       " 'Premium Apartment',\n",
       " 'Adjoined flat',\n",
       " 'DBSS']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(df_hdb[ (df_hdb['flat_type'] == '4 ROOM') & (df_hdb['town'] == 'BEDOK')]['flat_model'].unique())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 5\n",
    "1) create new field <b>floor_area_sqft</b> (Use conversion of 1 sqm = 10.7639 sqft) <br/>\n",
    "2) create new field <b>price_per_sqft</b> by using resale_price and floor_area_sqft"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "      <th>floor_area_sqft</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>174</td>\n",
       "      <td>ANG MO KIO AVE 4</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>60.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1986</td>\n",
       "      <td>255000.0</td>\n",
       "      <td>645.8340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>541</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1981</td>\n",
       "      <td>275000.0</td>\n",
       "      <td>731.9452</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>163</td>\n",
       "      <td>ANG MO KIO AVE 4</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>69.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1980</td>\n",
       "      <td>285000.0</td>\n",
       "      <td>742.7091</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>446</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1979</td>\n",
       "      <td>290000.0</td>\n",
       "      <td>731.9452</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>557</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1980</td>\n",
       "      <td>290000.0</td>\n",
       "      <td>731.9452</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Tranc_YearMonth        town flat_type block        street_name storey_range  \\\n",
       "0         2015-01  ANG MO KIO    3 ROOM   174   ANG MO KIO AVE 4     07 TO 09   \n",
       "1         2015-01  ANG MO KIO    3 ROOM   541  ANG MO KIO AVE 10     01 TO 03   \n",
       "2         2015-01  ANG MO KIO    3 ROOM   163   ANG MO KIO AVE 4     01 TO 03   \n",
       "3         2015-01  ANG MO KIO    3 ROOM   446  ANG MO KIO AVE 10     01 TO 03   \n",
       "4         2015-01  ANG MO KIO    3 ROOM   557  ANG MO KIO AVE 10     07 TO 09   \n",
       "\n",
       "   floor_area_sqm      flat_model  lease_commence_date  resale_price  \\\n",
       "0            60.0        Improved                 1986      255000.0   \n",
       "1            68.0  New Generation                 1981      275000.0   \n",
       "2            69.0  New Generation                 1980      285000.0   \n",
       "3            68.0  New Generation                 1979      290000.0   \n",
       "4            68.0  New Generation                 1980      290000.0   \n",
       "\n",
       "   floor_area_sqft  \n",
       "0         645.8340  \n",
       "1         731.9452  \n",
       "2         742.7091  \n",
       "3         731.9452  \n",
       "4         731.9452  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_hdb['floor_area_sqft'] = df_hdb['floor_area_sqm']*10.7639\n",
    "df_hdb.head (5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Tranc_YearMonth</th>\n",
       "      <th>town</th>\n",
       "      <th>flat_type</th>\n",
       "      <th>block</th>\n",
       "      <th>street_name</th>\n",
       "      <th>storey_range</th>\n",
       "      <th>floor_area_sqm</th>\n",
       "      <th>flat_model</th>\n",
       "      <th>lease_commence_date</th>\n",
       "      <th>resale_price</th>\n",
       "      <th>floor_area_sqft</th>\n",
       "      <th>price_per_sqft</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>174</td>\n",
       "      <td>ANG MO KIO AVE 4</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>60.0</td>\n",
       "      <td>Improved</td>\n",
       "      <td>1986</td>\n",
       "      <td>255000.0</td>\n",
       "      <td>645.8340</td>\n",
       "      <td>164687670.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>541</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1981</td>\n",
       "      <td>275000.0</td>\n",
       "      <td>731.9452</td>\n",
       "      <td>201284930.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>163</td>\n",
       "      <td>ANG MO KIO AVE 4</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>69.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1980</td>\n",
       "      <td>285000.0</td>\n",
       "      <td>742.7091</td>\n",
       "      <td>211672093.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>446</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>01 TO 03</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1979</td>\n",
       "      <td>290000.0</td>\n",
       "      <td>731.9452</td>\n",
       "      <td>212264108.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2015-01</td>\n",
       "      <td>ANG MO KIO</td>\n",
       "      <td>3 ROOM</td>\n",
       "      <td>557</td>\n",
       "      <td>ANG MO KIO AVE 10</td>\n",
       "      <td>07 TO 09</td>\n",
       "      <td>68.0</td>\n",
       "      <td>New Generation</td>\n",
       "      <td>1980</td>\n",
       "      <td>290000.0</td>\n",
       "      <td>731.9452</td>\n",
       "      <td>212264108.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Tranc_YearMonth        town flat_type block        street_name storey_range  \\\n",
       "0         2015-01  ANG MO KIO    3 ROOM   174   ANG MO KIO AVE 4     07 TO 09   \n",
       "1         2015-01  ANG MO KIO    3 ROOM   541  ANG MO KIO AVE 10     01 TO 03   \n",
       "2         2015-01  ANG MO KIO    3 ROOM   163   ANG MO KIO AVE 4     01 TO 03   \n",
       "3         2015-01  ANG MO KIO    3 ROOM   446  ANG MO KIO AVE 10     01 TO 03   \n",
       "4         2015-01  ANG MO KIO    3 ROOM   557  ANG MO KIO AVE 10     07 TO 09   \n",
       "\n",
       "   floor_area_sqm      flat_model  lease_commence_date  resale_price  \\\n",
       "0            60.0        Improved                 1986      255000.0   \n",
       "1            68.0  New Generation                 1981      275000.0   \n",
       "2            69.0  New Generation                 1980      285000.0   \n",
       "3            68.0  New Generation                 1979      290000.0   \n",
       "4            68.0  New Generation                 1980      290000.0   \n",
       "\n",
       "   floor_area_sqft  price_per_sqft  \n",
       "0         645.8340     164687670.0  \n",
       "1         731.9452     201284930.0  \n",
       "2         742.7091     211672093.5  \n",
       "3         731.9452     212264108.0  \n",
       "4         731.9452     212264108.0  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_hdb['price_per_sqft'] = df_hdb['resale_price']* df_hdb['floor_area_sqft']\n",
    "df_hdb.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Question 6"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. What is the **average floor_area_sqm** for 3-room flats from **Ang Mo Kio**|"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "763.8535578873002"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AvgFloorAreaSqm = df_hdb[((df_hdb['town'] == 'ANG MO KIO') & (df_hdb['flat_type'] == '3 ROOM'))]['floor_area_sqft'].mean()\n",
    "AvgFloorAreaSqm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. What is the **average resale price** for those 3-room flats from **Ang Mo Kio** that the flat's floor area is smaller than the average from part 1. above"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "324380.77525150904"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AvgResalePrice = df_hdb[(df_hdb['town'] == 'ANG MO KIO') & (df_hdb['flat_type'] == '3 ROOM' ) & (df_hdb['floor_area_sqm'] < AvgFloorAreaSqm)]['resale_price'].mean()\n",
    "AvgResalePrice"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exporting Data\n",
    "Save the processed file in Processed Data folder as <b>hdb_resale_full_processed.csv</b>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_hdb.to_csv('data/1_processed_data/hdb_resale_full_processed.csv', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "# Extra: Question X (Optional)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Get the data from the main table, with populations for each country from on this Wiki page:\n",
    "\n",
    "[https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population](https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population)\n",
    "\n",
    "You dataframe should look like this:\n",
    "\n",
    "![](data/image.jpg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Country / Dependency</th>\n",
       "      <th>Region</th>\n",
       "      <th>Population</th>\n",
       "      <th>Percentage of the world</th>\n",
       "      <th>Date</th>\n",
       "      <th>Source (official or from the United Nations)</th>\n",
       "      <th>Notes</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>–</td>\n",
       "      <td>World</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7952450000</td>\n",
       "      <td>100%</td>\n",
       "      <td>24 May 2022</td>\n",
       "      <td>UN projection[1]</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>China</td>\n",
       "      <td>Asia</td>\n",
       "      <td>1412600000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>31 Dec 2021</td>\n",
       "      <td>National annual estimate[2]</td>\n",
       "      <td>The population figure refers to mainland China...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>India</td>\n",
       "      <td>Asia</td>\n",
       "      <td>1409858100</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24 May 2022</td>\n",
       "      <td>National population clock[3]</td>\n",
       "      <td>The figure includes the population of Indian-a...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>United States</td>\n",
       "      <td>Americas</td>\n",
       "      <td>332697535</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24 May 2022</td>\n",
       "      <td>National population clock[4]</td>\n",
       "      <td>The figure includes the 50 states and the Dist...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>Indonesia</td>\n",
       "      <td>Asia[b]</td>\n",
       "      <td>272248500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1 Jul 2021</td>\n",
       "      <td>National annual estimate[5]</td>\n",
       "      <td>NaN</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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>–</td>\n",
       "      <td>Niue (New Zealand)</td>\n",
       "      <td>Oceania</td>\n",
       "      <td>1549</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1 Jul 2021</td>\n",
       "      <td>National annual projection[93]</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>–</td>\n",
       "      <td>Tokelau (New Zealand)</td>\n",
       "      <td>Oceania</td>\n",
       "      <td>1501</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1 Jul 2021</td>\n",
       "      <td>National annual projection[93]</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>195</td>\n",
       "      <td>Vatican City</td>\n",
       "      <td>Europe</td>\n",
       "      <td>825</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1 Feb 2019</td>\n",
       "      <td>Monthly national estimate[197]</td>\n",
       "      <td>The total population of 825 consisted of 453 r...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>–</td>\n",
       "      <td>Cocos (Keeling) Islands (Australia)</td>\n",
       "      <td>Oceania</td>\n",
       "      <td>573</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30 Jun 2020</td>\n",
       "      <td>National annual estimate[196]</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>241</th>\n",
       "      <td>–</td>\n",
       "      <td>Pitcairn Islands (United Kingdom)</td>\n",
       "      <td>Oceania</td>\n",
       "      <td>40</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1 Jan 2021</td>\n",
       "      <td>National annual estimate[198]</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>242 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Rank                 Country / Dependency    Region  Population  \\\n",
       "0      –                                World       NaN  7952450000   \n",
       "1      1                                China      Asia  1412600000   \n",
       "2      2                                India      Asia  1409858100   \n",
       "3      3                        United States  Americas   332697535   \n",
       "4      4                            Indonesia   Asia[b]   272248500   \n",
       "..   ...                                  ...       ...         ...   \n",
       "237    –                   Niue (New Zealand)   Oceania        1549   \n",
       "238    –                Tokelau (New Zealand)   Oceania        1501   \n",
       "239  195                         Vatican City    Europe         825   \n",
       "240    –  Cocos (Keeling) Islands (Australia)   Oceania         573   \n",
       "241    –    Pitcairn Islands (United Kingdom)   Oceania          40   \n",
       "\n",
       "    Percentage of the world         Date  \\\n",
       "0                      100%  24 May 2022   \n",
       "1                       NaN  31 Dec 2021   \n",
       "2                       NaN  24 May 2022   \n",
       "3                       NaN  24 May 2022   \n",
       "4                       NaN   1 Jul 2021   \n",
       "..                      ...          ...   \n",
       "237                     NaN   1 Jul 2021   \n",
       "238                     NaN   1 Jul 2021   \n",
       "239                     NaN   1 Feb 2019   \n",
       "240                     NaN  30 Jun 2020   \n",
       "241                     NaN   1 Jan 2021   \n",
       "\n",
       "    Source (official or from the United Nations)  \\\n",
       "0                               UN projection[1]   \n",
       "1                    National annual estimate[2]   \n",
       "2                   National population clock[3]   \n",
       "3                   National population clock[4]   \n",
       "4                    National annual estimate[5]   \n",
       "..                                           ...   \n",
       "237               National annual projection[93]   \n",
       "238               National annual projection[93]   \n",
       "239               Monthly national estimate[197]   \n",
       "240                National annual estimate[196]   \n",
       "241                National annual estimate[198]   \n",
       "\n",
       "                                                 Notes  \n",
       "0                                                  NaN  \n",
       "1    The population figure refers to mainland China...  \n",
       "2    The figure includes the population of Indian-a...  \n",
       "3    The figure includes the 50 states and the Dist...  \n",
       "4                                                  NaN  \n",
       "..                                                 ...  \n",
       "237                                                NaN  \n",
       "238                                                NaN  \n",
       "239  The total population of 825 consisted of 453 r...  \n",
       "240                                                NaN  \n",
       "241                                                NaN  \n",
       "\n",
       "[242 rows x 8 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table = pd.read_html ('https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population')\n",
    "table [0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "name": "DC Bootcamp Week 17.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}

# data[].attributes.body
DC_Bootcamp_Week_6, apologies for late submission, busy week.

# data[].attributes.body
DC_Bootcamp_Week_6_submission