{ "cells": [ { "cell_type": "markdown", "id": "db28a428", "metadata": {}, "source": [ "# Confirmed Exoplanet Census\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `exoplanets.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `exoplanets.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "363a4cda", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"exoplanets.csv\")\n", "df[\"disc_year\"] = pd.to_numeric(df[\"disc_year\"], errors=\"coerce\")\n", "print(df.shape)" ] }, { "cell_type": "markdown", "id": "325de123", "metadata": {}, "source": [ "## 2. Shape, types and missing values" ] }, { "cell_type": "code", "id": "32baba39", "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": "f9eba2a3", "metadata": {}, "source": [ "## 4. The radius valley\n", "\n", "Plot the radius distribution split by equilibrium-temperature band." ] }, { "cell_type": "code", "id": "2789bd0b", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import numpy as np\n", "\n", "ax = (df.dropna(subset=[\"pl_rade\", \"teq_class\"])\n", " .query(\"pl_rade < 20\")\n", " .hist(column=\"pl_rade\", by=\"teq_class\", bins=60, figsize=(14, 8), sharex=True))\n", "for a in np.ravel(ax):\n", " a.set_xlabel(\"Planet radius (Earth radii)\")\n", " a.set_ylabel(\"Planets\")" ] }, { "cell_type": "markdown", "id": "dfbb8fbf", "metadata": {}, "source": [ "## 5. Mass–radius diagram\n", "\n", "Rocky planets follow a steep mass–radius relation; gas giants flatten out." ] }, { "cell_type": "code", "id": "5b73d51a", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "sub = df.dropna(subset=[\"pl_rade\", \"pl_bmasse\"]).query(\"pl_rade < 20 and pl_bmasse < 5000\")\n", "sub.plot.scatter(x=\"pl_rade\", y=\"pl_bmasse\", c=\"pl_eqt\", cmap=\"inferno\", s=12,\n", " logy=True, figsize=(9, 6), colorbar=True)" ] }, { "cell_type": "markdown", "id": "4177293f", "metadata": {}, "source": [ "## 6. Discovery timeline by method" ] }, { "cell_type": "code", "id": "588b7426", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "by_year = (df.dropna(subset=[\"disc_year\"])\n", " .groupby([\"disc_year\", \"discoverymethod\"]).size().unstack(fill_value=0))\n", "by_year.plot.area(figsize=(12, 6), cmap=\"tab20\")" ] }, { "cell_type": "markdown", "id": "5fefa62b", "metadata": {}, "source": [ "## 7. Habitable-zone candidates" ] }, { "cell_type": "code", "id": "7d20091f", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "hz = df[df[\"in_habitable_zone\"].astype(str).str.lower() == \"true\"]\n", "print(f\"{len(hz):,} planets in the conservative habitable zone\")\n", "hz.groupby([\"star_type_group\", \"planet_type\"]).size().sort_values(ascending=False).head(15)" ] }, { "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 }