{ "cells": [ { "cell_type": "markdown", "id": "6d46bcd2", "metadata": {}, "source": [ "# World Postal Code Directory\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `postal_codes.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `postal_codes.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "5874fd30", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"postal_codes.csv\", dtype={\"postal_code\": str}, low_memory=False)\n", "print(df.shape)" ] }, { "cell_type": "markdown", "id": "325de123", "metadata": {}, "source": [ "## 2. Shape, types and missing values" ] }, { "cell_type": "code", "id": "6eb42bc8", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "print(f\"{df.shape[0]:,} rows x {df.shape[1]} columns\")\n", "\n", "missing = df.isna().mean().mul(100).sort_values(ascending=False)\n", "missing[missing > 0].round(1).to_frame(\"missing_%\").head(15)" ] }, { "cell_type": "markdown", "id": "f2d963fe", "metadata": {}, "source": [ "## 3. Numeric summary" ] }, { "cell_type": "code", "id": "aa2f8fd4", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.describe(include='number').T.round(2).head(20)" ] }, { "cell_type": "markdown", "id": "b96932fe", "metadata": {}, "source": [ "## 4. Records by country" ] }, { "cell_type": "code", "id": "d1fcce62", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"country_name\"].value_counts().head(15).to_frame(\"postal_records\")" ] }, { "cell_type": "markdown", "id": "dc07af50", "metadata": {}, "source": [ "## 5. Postal code length distribution" ] }, { "cell_type": "code", "id": "b958164f", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"postal_length\"].value_counts().sort_index().head(12).to_frame(\"codes\")" ] }, { "cell_type": "markdown", "id": "eefadcb2", "metadata": {}, "source": [ "## 6. Numeric vs alphanumeric" ] }, { "cell_type": "code", "id": "63659e72", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"is_numeric_postal\"].value_counts(normalize=True).mul(100).round(1)" ] }, { "cell_type": "markdown", "id": "9df55b32", "metadata": {}, "source": [ "## 7. Administrative depth" ] }, { "cell_type": "code", "id": "3d04fe21", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"admin_depth\"].value_counts().sort_index().to_frame(\"records\")" ] }, { "cell_type": "markdown", "id": "d11c50d9", "metadata": {}, "source": [ "## 8. Map sample" ] }, { "cell_type": "code", "id": "7973ff27", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "sample = df.dropna(subset=[\"latitude\", \"longitude\"]).sample(5000, random_state=0)\n", "sample.plot.scatter(x=\"longitude\", y=\"latitude\", s=1, alpha=0.3, figsize=(11, 6))" ] }, { "cell_type": "markdown", "id": "6e43770c", "metadata": {}, "source": [ "## Next steps\n", "\n", "See `KAGGLE.md` for analysis ideas, caveats and provenance." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.11", "mimetype": "text/x-python", "file_extension": ".py", "codemirror_mode": { "name": "ipython", "version": 3 }, "pygments_lexer": "ipython3", "nbconvert_exporter": "python" } }, "nbformat": 4, "nbformat_minor": 5 }