{ "cells": [ { "cell_type": "markdown", "id": "7da4e307", "metadata": {}, "source": [ "# Python Package Ecosystem\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `pypi_packages.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `pypi_packages.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "6e43df41", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"pypi_packages.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": "39973095", "metadata": {}, "source": [ "## 4. Download concentration" ] }, { "cell_type": "code", "id": "cd1bc127", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "top = df.sort_values(\"monthly_downloads\", ascending=False).head(20)\n", "top.set_index(\"project\")[\"monthly_downloads\"].plot(kind=\"bar\", figsize=(10, 4), title=\"Top 20 by 30-day downloads\")" ] }, { "cell_type": "markdown", "id": "57b1af2e", "metadata": {}, "source": [ "## 5. Licence mix" ] }, { "cell_type": "code", "id": "1996a9ff", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"license_class\")[\"monthly_downloads\"].agg([\"count\", \"sum\"]).sort_values(\"sum\", ascending=False)" ] }, { "cell_type": "markdown", "id": "d18d6640", "metadata": {}, "source": [ "## 6. Release cadence" ] }, { "cell_type": "code", "id": "13838fdd", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"release_cadence\"].value_counts().to_frame(\"packages\")" ] }, { "cell_type": "markdown", "id": "078fa60b", "metadata": {}, "source": [ "## 7. Dependencies vs downloads" ] }, { "cell_type": "code", "id": "efc39228", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "sub = df.dropna(subset=[\"dependency_count\", \"monthly_downloads\"])\n", "sub.plot.scatter(x=\"dependency_count\", y=\"monthly_downloads\", s=4, alpha=0.3, logy=True, figsize=(8, 5))" ] }, { "cell_type": "markdown", "id": "e4a6473e", "metadata": {}, "source": [ "## 8. Staleness" ] }, { "cell_type": "code", "id": "b6a526e4", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.nlargest(15, \"days_since_release\")[[\"project\", \"days_since_release\", \"monthly_downloads\", \"development_status\"]]" ] }, { "cell_type": "markdown", "id": "7c563f68", "metadata": {}, "source": [ "## 9. Packaging completeness" ] }, { "cell_type": "code", "id": "51857569", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"has_wheel\")[\"monthly_downloads\"].median().to_frame(\"median_downloads\")" ] }, { "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 }