{ "cells": [ { "cell_type": "markdown", "id": "b7442fec", "metadata": {}, "source": [ "# Global Power Plant Inventory\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `power_plants.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `power_plants.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "22af8838", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"power_plants.csv\", low_memory=False)\n", "df[\"capacity_mw\"] = pd.to_numeric(df[\"capacity_mw\"], errors=\"coerce\")\n", "print(df.shape)" ] }, { "cell_type": "markdown", "id": "325de123", "metadata": {}, "source": [ "## 2. Shape, types and missing values" ] }, { "cell_type": "code", "id": "795b95df", "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": "529472ba", "metadata": {}, "source": [ "## 4. Capacity by fuel group" ] }, { "cell_type": "code", "id": "2122bcd3", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "(df.groupby(\"fuel_group\")[\"capacity_mw\"].sum() / 1000\n", " ).round(1).sort_values(ascending=False).to_frame(\"capacity_gw\")" ] }, { "cell_type": "markdown", "id": "801559f7", "metadata": {}, "source": [ "## 5. Where the capacity sits\n", "\n", "Top 15 countries by total installed capacity." ] }, { "cell_type": "code", "id": "120b9d95", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "top = (df.groupby(\"country_long\")[\"capacity_mw\"].sum() / 1000).sort_values(ascending=False).head(15)\n", "top.plot.barh(figsize=(8, 6))" ] }, { "cell_type": "markdown", "id": "674e596a", "metadata": {}, "source": [ "## 6. Observed capacity factors\n", "\n", "Only plants that report generation have a value — compare fuels." ] }, { "cell_type": "code", "id": "60f54536", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "sub = df.dropna(subset=[\"mean_capacity_factor_pct\"])\n", "sub.boxplot(column=\"mean_capacity_factor_pct\", by=\"fuel_group\", figsize=(11, 5), rot=30)" ] }, { "cell_type": "markdown", "id": "9ddc5f21", "metadata": {}, "source": [ "## 7. Ageing fleet" ] }, { "cell_type": "code", "id": "3d27a170", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.dropna(subset=[\"plant_age_years\"]).query(\"plant_age_years >= 0\").hist(\n", " column=\"plant_age_years\", by=\"fuel_group\", bins=30, figsize=(14, 8), sharex=True)" ] }, { "cell_type": "markdown", "id": "e140d503", "metadata": {}, "source": [ "## 8. Renewables share of capacity by region" ] }, { "cell_type": "code", "id": "d0036af7", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "(df.groupby([\"region\", \"fuel_group\"])[\"capacity_mw\"].sum()\n", " .unstack(fill_value=0).pipe(lambda t: t.div(t.sum(axis=1), axis=0) * 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 }