{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Python Data Structures: Lists, Tuples, Sets, and Dictionaries\n",
        "Practice notebook for the Xenors lesson: https://xenors.in/data-science/python-basics-data-structures/\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import pandas as pd\n",
        "df = pd.read_csv('../datasets/python-basics-data-structures.csv')\n",
        "df.head()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Baseline example\n",
        "Expected checkpoint: Run the cell and inspect the printed values before changing anything.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "cities = ['Delhi', 'Mumbai', 'Delhi']\n",
        "unique_cities = set(cities)\n",
        "labels = {'M': 'Male', 'F': 'Female'}\n",
        "columns = ['age', 'income', 'city']\n",
        "point = (23.1, 72.6)\n",
        "print(unique_cities, labels['F'])\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Inspect data before transforming it\n",
        "Expected checkpoint: (30, 5)\nColumn types are printed, followed by the first three rows.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import pandas as pd\n",
        "\n",
        "df = pd.read_csv('practice.csv')\n",
        "print(df.shape)\n",
        "print(df.dtypes)\n",
        "print(df.head(3).to_string(index=False))\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Check missing values explicitly\n",
        "Expected checkpoint: Only columns with at least one missing value are listed.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "missing = df.isna().sum().sort_values(ascending=False)\n",
        "print(missing[missing.gt(0)])\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Create a reproducible summary\n",
        "Expected checkpoint: A compact numeric summary appears with one row per numeric column.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "summary = df.select_dtypes('number').agg(['count','mean','median','min','max']).T\n",
        "print(summary.round(2))\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Test one edge case\n",
        "Expected checkpoint: The row count and duplicate count make the check visible instead of implicit.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "test = df.copy()\n",
        "if len(test):\n",
        "    test.iloc[0, 0] = test.iloc[0, 0]\n",
        "print('rows:', len(test), 'duplicates:', test.duplicated().sum())\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.x"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}