{ "cells": [ { "cell_type": "markdown", "id": "0faa43fd", "metadata": {}, "source": [ "# Global Biodiversity Occurrences\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `occurrences.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `occurrences.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "eab6c3a0", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"occurrences.csv\", low_memory=False)\n", "print(df.shape)\n", "df[[\"scientificName\", \"kingdom\", \"country_name\", \"decimalLatitude\", \"year\"]].head()" ] }, { "cell_type": "markdown", "id": "325de123", "metadata": {}, "source": [ "## 2. Shape, types and missing values" ] }, { "cell_type": "code", "id": "e8f80bc1", "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": "8510caed", "metadata": {}, "source": [ "## 4. Records per kingdom" ] }, { "cell_type": "code", "id": "efe00995", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"kingdom\"].value_counts().head(10).plot.bar(figsize=(8, 4))" ] }, { "cell_type": "markdown", "id": "910b4588", "metadata": {}, "source": [ "## 5. Latitudinal diversity gradient\n", "\n", "Records per 5-degree band of absolute latitude." ] }, { "cell_type": "code", "id": "45b88855", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "bins = range(0, 95, 5)\n", "band = pd.cut(df[\"abs_latitude\"], bins=bins)\n", "band.value_counts().sort_index().plot.bar(figsize=(11, 4))" ] }, { "cell_type": "markdown", "id": "208187ad", "metadata": {}, "source": [ "## 6. Sampling bias between countries" ] }, { "cell_type": "code", "id": "94fab4d2", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"country_name\").agg(records=(\"key\", \"count\"),\n", " species=(\"species\", \"nunique\"),\n", " families=(\"family\", \"nunique\")).sort_values(\"records\", ascending=False)" ] }, { "cell_type": "markdown", "id": "35fe546b", "metadata": {}, "source": [ "## 7. Data quality flags" ] }, { "cell_type": "code", "id": "47f65221", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"n_issues\"].value_counts().sort_index().plot.bar(figsize=(8, 4))\n", "df[\"has_issues\"].value_counts(normalize=True).round(3)" ] }, { "cell_type": "markdown", "id": "e682571b", "metadata": {}, "source": [ "## 8. Record type mix by region" ] }, { "cell_type": "code", "id": "c01dc0a0", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "(df.groupby([\"region\", \"basis_group\"]).size()\n", " .unstack(fill_value=0).pipe(lambda t: t.div(t.sum(axis=1), axis=0) * 100).round(1))" ] }, { "cell_type": "markdown", "id": "aacabb11", "metadata": {}, "source": [ "## 9. Observation years" ] }, { "cell_type": "code", "id": "fb209d5e", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"year\"].dropna().astype(int).plot.hist(bins=40, figsize=(10, 4))" ] }, { "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 }