{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# pandas Fundamentals\n",
        "\n**Opening question:** How can a rectangular dataset preserve labels, dates, and missing values while supporting fast analysis?\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import pandas as pd\n",
        "\n",
        "df = pd.DataFrame({\n",
        "    \"province\": [\"ON\", \"QC\", \"BC\", \"ON\"],\n",
        "    \"income\": [62_000, 58_000, 65_000, 71_000],\n",
        "    \"employed\": [True, True, False, True],\n",
        "})\n",
        "print(df.shape)\n",
        "print(df.dtypes.astype(str).to_dict())\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The structure reveals four observations and three variables with different data types.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "high_income = (\n",
        "    df.loc[df[\"income\"] >= 60_000]\n",
        "      .assign(income_thousands=lambda x: x[\"income\"] / 1_000)\n",
        "      .sort_values(\"income\", ascending=False)\n",
        ")\n",
        "print(high_income[[\"province\", \"income_thousands\"]])\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The chain reads as a sequence of analytical decisions and leaves the original DataFrame unchanged.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Verified source output\n",
        "\n",
        "```text\n(4, 3) {'province': 'object', 'income': 'int64', 'employed': 'bool'}\n```\n\n```text\nprovince income_thousands 3 ON 71.0 2 BC 65.0 0 ON 62.0\n```\n\n```text\n(4, 3)\n{'province': 'object', 'income': 'int64', 'employed': 'bool'}\n```\n\n```text\nprovince  income_thousands\n3       ON              71.0\n2       BC              65.0\n0       ON              62.0\n```\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3"
    },
    "ceteris_lab": {
      "course_slug": "fundamentals-python-econometrics",
      "source_derived": true,
      "course_title": "Fundamentals of Python for Financial Econometrics",
      "chapter": 9,
      "source_origin": "source-derived"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
