{ "cells": [ { "cell_type": "markdown", "id": "1d8ad1c8", "metadata": {}, "source": [ "# Global Clinical Trials Registry\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `clinical_trials.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `clinical_trials.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "89948490", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"clinical_trials.csv\", low_memory=False)\n", "df[\"start_date\"] = pd.to_datetime(df[\"start_date\"], errors=\"coerce\")\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": "0d231193", "metadata": {}, "source": [ "## 4. Status and phase mix" ] }, { "cell_type": "code", "id": "2121257e", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"overall_status\"].value_counts().head(10).to_frame(\"trials\")" ] }, { "cell_type": "code", "id": "db23e6f7", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "(df.groupby([\"phase_clean\", \"overall_status\"]).size()\n", " .unstack(fill_value=0).head(10))" ] }, { "cell_type": "markdown", "id": "17bab63b", "metadata": {}, "source": [ "## 5. Who runs trials\\n\\nLead sponsor class, cleaned up." ] }, { "cell_type": "code", "id": "0e79ce65", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"lead_sponsor_class\"].value_counts().to_frame(\"trials\")" ] }, { "cell_type": "markdown", "id": "67ebc447", "metadata": {}, "source": [ "## 6. Reporting lag\\n\\nDays between completion and first results posting." ] }, { "cell_type": "code", "id": "2a35cbd7", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "done = df.dropna(subset=[\"completion_date\", \"results_first_posted\"]).copy()\n", "done[\"lag_days\"] = (pd.to_datetime(done[\"results_first_posted\"], format=\"mixed\", errors=\"coerce\")\n", " - pd.to_datetime(done[\"completion_date\"], format=\"mixed\", errors=\"coerce\")).dt.days\n", "done[\"lag_days\"].clip(lower=0).describe().round(0).to_frame(\"days\")" ] }, { "cell_type": "markdown", "id": "9d27ae47", "metadata": {}, "source": [ "## 7. Enrollment by phase" ] }, { "cell_type": "code", "id": "06e57d90", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"phase_clean\")[\"enrollment_count\"].median().sort_values().to_frame(\"median_enrollment\")" ] }, { "cell_type": "markdown", "id": "2c138599", "metadata": {}, "source": [ "## 8. Most-studied conditions" ] }, { "cell_type": "code", "id": "0e6590e3", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"conditions\"].str.split(\";\").explode().str.strip().value_counts().head(15).to_frame(\"trials\")" ] }, { "cell_type": "markdown", "id": "2feaf4dd", "metadata": {}, "source": [ "## 9. Trials starting per year" ] }, { "cell_type": "code", "id": "07e743d7", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"start_year\"].dropna().astype(int).value_counts().sort_index().plot(\n", " kind=\"line\", figsize=(10, 4), title=\"Trial starts by year (sample)\")" ] }, { "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 }