{ "cells": [ { "cell_type": "markdown", "id": "0aec4d8d", "metadata": {}, "source": [ "# Global Weather Station Network\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `weather_stations.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `weather_stations.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "1c05049c", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"weather_stations.csv\", dtype={\"station_id\": 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": "e56c98ca", "metadata": {}, "source": [ "## 4. Stations by country" ] }, { "cell_type": "code", "id": "bcef1c6d", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"country_name\"].value_counts().head(15).to_frame(\"stations\")" ] }, { "cell_type": "markdown", "id": "8ce5ba93", "metadata": {}, "source": [ "## 5. Record length distribution" ] }, { "cell_type": "code", "id": "8ba01718", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"record_years\"].dropna().clip(upper=150).hist(bins=50, figsize=(8, 4))" ] }, { "cell_type": "markdown", "id": "3683adee", "metadata": {}, "source": [ "## 6. Element coverage" ] }, { "cell_type": "code", "id": "82c2ba00", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "for c in [\"has_precipitation\", \"has_temperature\", \"has_snow\", \"has_wind\"]:\n", " print(c, round((df[c].astype(str).str.lower() == \"true\").mean() * 100, 1), \"%\")" ] }, { "cell_type": "markdown", "id": "c25c9a59", "metadata": {}, "source": [ "## 7. Map" ] }, { "cell_type": "code", "id": "1946a189", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "sub = df.dropna(subset=[\"latitude\", \"longitude\"])\n", "sub.plot.scatter(x=\"longitude\", y=\"latitude\", s=1, alpha=0.3, figsize=(11, 6))" ] }, { "cell_type": "markdown", "id": "e3a252c5", "metadata": {}, "source": [ "## 8. Active stations by decade started" ] }, { "cell_type": "code", "id": "128d2c1c", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "(df[\"first_year\"] // 10 * 10).value_counts().sort_index().tail(15).plot(kind=\"bar\", figsize=(10, 4))" ] }, { "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 }