{ "cells": [ { "cell_type": "markdown", "id": "38745ba7", "metadata": {}, "source": [ "# Hurricane Database 1851–2024\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `hurricanes.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `hurricanes.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "54abf4aa", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"hurricanes.csv\", low_memory=False)\n", "df[\"record_time_utc\"] = pd.to_datetime(df[\"record_time_utc\"], errors=\"coerce\")\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": "059cb35a", "metadata": {}, "source": [ "## 4. Storms and waypoints by decade" ] }, { "cell_type": "code", "id": "92ce0bfb", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"decade\").agg(storms=(\"storm_id\", \"nunique\"),\n", " waypoints=(\"storm_id\", \"size\")).tail(12)" ] }, { "cell_type": "markdown", "id": "72097b1f", "metadata": {}, "source": [ "## 5. Peak category distribution" ] }, { "cell_type": "code", "id": "a39b39e5", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "(df.drop_duplicates(\"storm_id\")[\"storm_peak_category\"]\n", " .value_counts().reindex([\"Tropical Depression\", \"Tropical Storm\", \"Category 1\", \"Category 2\",\n", " \"Category 3\", \"Category 4\", \"Category 5\"]))" ] }, { "cell_type": "markdown", "id": "3841ce58", "metadata": {}, "source": [ "## 6. Accumulated Cyclone Energy by decade" ] }, { "cell_type": "code", "id": "cfcfe5c6", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "ace = df.drop_duplicates(\"storm_id\").groupby(\"decade\")[\"storm_ace\"].sum()\n", "ace.tail(15).plot(kind=\"bar\", figsize=(10, 4), title=\"Total ACE by decade\")" ] }, { "cell_type": "markdown", "id": "58102f26", "metadata": {}, "source": [ "## 7. A single track, mapped" ] }, { "cell_type": "code", "id": "183cd84c", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "storm = df[df[\"storm_id\"] == df.loc[df[\"storm_max_wind_kt\"].idxmax(), \"storm_id\"]]\n", "ax = storm.plot(x=\"longitude\", y=\"latitude\", figsize=(8, 6), legend=False,\n", " title=f\"Track of {storm['storm_name'].iloc[0]} ({storm['storm_year'].iloc[0]})\")\n", "ax.set_xlabel(\"longitude\"); ax.set_ylabel(\"latitude\")" ] }, { "cell_type": "markdown", "id": "11495f9e", "metadata": {}, "source": [ "## 8. Wind vs pressure" ] }, { "cell_type": "code", "id": "ab4091ce", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "sub = df.dropna(subset=[\"min_pressure_mb\", \"max_wind_kt\"])\n", "sub.plot.scatter(x=\"min_pressure_mb\", y=\"max_wind_kt\", s=4, alpha=0.2, figsize=(8, 5))" ] }, { "cell_type": "markdown", "id": "d4451304", "metadata": {}, "source": [ "## 9. Translation speed over time" ] }, { "cell_type": "code", "id": "afaec914", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"decade\")[\"movement_speed_kmh\"].median().tail(15).plot(\n", " kind=\"line\", marker=\"o\", figsize=(10, 4), title=\"Median translation speed by decade\")" ] }, { "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 }