{ "cells": [ { "cell_type": "markdown", "id": "fec44632", "metadata": {}, "source": [ "# Near-Earth Asteroids\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `near_earth_asteroids.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `near_earth_asteroids.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "f07b176d", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"near_earth_asteroids.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": "1f8956f4", "metadata": {}, "source": [ "## 4. Orbit classes" ] }, { "cell_type": "code", "id": "ca804fb3", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"orbit_class\"].value_counts().to_frame(\"objects\")" ] }, { "cell_type": "markdown", "id": "8149c33f", "metadata": {}, "source": [ "## 5. Semi-major axis vs eccentricity" ] }, { "cell_type": "code", "id": "df6030cf", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.plot.scatter(x=\"semi_major_axis_au\", y=\"eccentricity\", s=3, alpha=0.25, figsize=(8, 5))" ] }, { "cell_type": "markdown", "id": "7f43462d", "metadata": {}, "source": [ "## 6. Size distribution" ] }, { "cell_type": "code", "id": "6ea7545f", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "sizes = df[\"diameter_km\"].dropna()\n", "import numpy as np\n", "np.logspace(0, 3, 40) # reference decades\n", "sizes[sizes > 0].plot(kind=\"hist\", bins=np.logspace(-3, 1.4, 40), logy=True, figsize=(10, 4),\n", " title=\"Diameter distribution (km, log bins)\")" ] }, { "cell_type": "markdown", "id": "5097e057", "metadata": {}, "source": [ "## 7. Potentially hazardous objects" ] }, { "cell_type": "code", "id": "c9f44710", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"orbit_class\")[\"is_potentially_hazardous\"].apply(\n", " lambda s: (s.astype(str).str.lower() == \"true\").mean() * 100).round(1).to_frame(\"pha_%\")" ] }, { "cell_type": "markdown", "id": "6183ee71", "metadata": {}, "source": [ "## 8. Closest approaches" ] }, { "cell_type": "code", "id": "beeacf45", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.nsmallest(15, \"earth_moid_au\")[[\"full_name\", \"earth_moid_au\", \"h_magnitude_size_m\", \"orbit_class\"]]" ] }, { "cell_type": "markdown", "id": "f02f0e2a", "metadata": {}, "source": [ "## 9. Data completeness by size" ] }, { "cell_type": "code", "id": "60f149ab", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"size_bin\"] = pd.cut(df[\"diameter_km\"], [0, .1, .5, 1, 5, 50])\n", "df.groupby(\"size_bin\", observed=True)[[\"has_albedo\", \"has_spectral_type\"]].apply(\n", " lambda t: t.apply(lambda s: (s.astype(str).str.lower() == \"true\").mean()) * 100).round(1)" ] }, { "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 }