{ "cells": [ { "cell_type": "markdown", "id": "8e6eed2a", "metadata": {}, "source": [ "# U.S. Tornado Catalog 1950–2024\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `tornadoes.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `tornadoes.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "fe2cc775", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"tornadoes.csv\", 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": "950f8aaf", "metadata": {}, "source": [ "## 4. Tornadoes per year" ] }, { "cell_type": "code", "id": "32a46f35", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"yr\").size().plot(figsize=(11, 4), title=\"Recorded tornadoes per year\")" ] }, { "cell_type": "markdown", "id": "6959bcbb", "metadata": {}, "source": [ "## 5. Ratings" ] }, { "cell_type": "code", "id": "429d7227", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"magnitude_label\"].value_counts().head(14).to_frame(\"tornadoes\")" ] }, { "cell_type": "markdown", "id": "c8ea63fb", "metadata": {}, "source": [ "## 6. Where they happen\\n\\nTop 15 states by count." ] }, { "cell_type": "code", "id": "2a8a2a95", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"state_name\"].value_counts().head(15).to_frame(\"tornadoes\")" ] }, { "cell_type": "markdown", "id": "91fcb8b2", "metadata": {}, "source": [ "## 7. Seasonality" ] }, { "cell_type": "code", "id": "75238557", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"month_name\"].value_counts().reindex([\n", " \"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\",\"August\",\"September\",\"October\",\"November\",\"December\"]\n", ").plot(kind=\"bar\", figsize=(10, 4), title=\"Tornadoes by month\")" ] }, { "cell_type": "markdown", "id": "e1ae38cd", "metadata": {}, "source": [ "## 8. Casualties vs magnitude" ] }, { "cell_type": "code", "id": "53e893cf", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"magnitude_label\")[[\"fat\", \"inj\"]].sum().sort_values(\"fat\", ascending=False).head(12)" ] }, { "cell_type": "markdown", "id": "5f3cdddd", "metadata": {}, "source": [ "## 9. Path length by rating" ] }, { "cell_type": "code", "id": "b609feb1", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.boxplot(column=\"len\", by=\"magnitude_label\", figsize=(11, 5), rot=45)" ] }, { "cell_type": "markdown", "id": "29677c56", "metadata": {}, "source": [ "## 10. F vs EF era" ] }, { "cell_type": "code", "id": "3aadf186", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"scale\")[\"mag\"].agg([\"count\", \"mean\", \"median\"]).round(2)" ] }, { "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 }