{ "cells": [ { "cell_type": "markdown", "id": "81eccfe7", "metadata": {}, "source": [ "# World Airport Network\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `airports.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `airports.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "a3222460", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"airports.csv\", low_memory=False)\n", "df[\"routes\"] = df[\"n_routes_out\"].fillna(0) + df[\"n_routes_in\"].fillna(0)\n", "print(df.shape)\n", "df.head(3)" ] }, { "cell_type": "markdown", "id": "325de123", "metadata": {}, "source": [ "## 2. Shape, types and missing values" ] }, { "cell_type": "code", "id": "c995eab3", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "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": "48da4abf", "metadata": {}, "source": [ "## 4. Busiest airports by route records" ] }, { "cell_type": "code", "id": "9e1066a1", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.nlargest(15, \"routes\")[[\"name\", \"city\", \"country\", \"iata\", \"routes\",\n", " \"n_destinations\", \"n_airlines\"]].set_index(\"iata\")" ] }, { "cell_type": "markdown", "id": "36a65583", "metadata": {}, "source": [ "## 5. Hub classes\n", "\n", "How many airports sit in each network role?" ] }, { "cell_type": "code", "id": "d4a31929", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"hub_class\"].value_counts().plot.bar(figsize=(8, 4))" ] }, { "cell_type": "markdown", "id": "36d83338", "metadata": {}, "source": [ "## 6. Long-haul map\n", "\n", "Airports with the longest non-stop routes." ] }, { "cell_type": "code", "id": "906036a7", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "long = df.dropna(subset=[\"max_route_distance_km\"]).nlargest(20, \"max_route_distance_km\")\n", "long[[\"name\", \"city\", \"country\", \"max_route_distance_km\", \"farthest_destination\"]].set_index(\"name\")" ] }, { "cell_type": "markdown", "id": "8a8606ef", "metadata": {}, "source": [ "## 7. Connectivity vs wealth" ] }, { "cell_type": "code", "id": "5fe95413", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "sub = df.dropna(subset=[\"country_gdp_per_capita_usd\", \"routes_per_million_people\"])\n", "sub = sub[sub[\"routes\"] > 0]\n", "sub.plot.scatter(x=\"country_gdp_per_capita_usd\", y=\"routes_per_million_people\", logx=True, s=10, figsize=(8, 5))" ] }, { "cell_type": "markdown", "id": "552e537e", "metadata": {}, "source": [ "## 8. Domestic vs international mix for the top 25 airports" ] }, { "cell_type": "code", "id": "5675896b", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "top = df.nlargest(25, \"routes\").set_index(\"iata\")\n", "(top[[\"n_domestic_routes\", \"n_routes_out\"]]\n", " .assign(international=lambda t: t[\"n_routes_out\"] - t[\"n_domestic_routes\"])\n", " [[\"n_domestic_routes\", \"international\"]]\n", " .plot.barh(stacked=True, figsize=(9, 7)))" ] }, { "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 }