{ "cells": [ { "cell_type": "markdown", "id": "3eaf9cf5", "metadata": {}, "source": [ "# NYC 311 Service Requests\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `nyc_311_requests.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `nyc_311_requests.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "e9eb657c", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"nyc_311_requests.csv\", low_memory=False, parse_dates=[\"created_date\", \"closed_date\"])\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": "2330f38e", "metadata": {}, "source": [ "## 4. Top complaint types" ] }, { "cell_type": "code", "id": "d2b3120e", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"complaint_type\"].value_counts().head(15).to_frame(\"requests\")" ] }, { "cell_type": "markdown", "id": "a83aea0f", "metadata": {}, "source": [ "## 5. Requests by borough" ] }, { "cell_type": "code", "id": "def02710", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"borough\"].value_counts().to_frame(\"requests\")" ] }, { "cell_type": "markdown", "id": "98c7ad82", "metadata": {}, "source": [ "## 6. Response time distribution" ] }, { "cell_type": "code", "id": "a749e0ef", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"response_days\"].dropna().clip(upper=30).hist(bins=40, figsize=(9, 4))" ] }, { "cell_type": "markdown", "id": "026b769a", "metadata": {}, "source": [ "## 7. Complaint categories" ] }, { "cell_type": "code", "id": "7cbb255b", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"complaint_category\"].value_counts().to_frame(\"requests\")" ] }, { "cell_type": "markdown", "id": "f53edd78", "metadata": {}, "source": [ "## 8. Hourly pattern" ] }, { "cell_type": "code", "id": "807074a6", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"hour\")[\"unique_key\"].count().plot(kind=\"bar\", 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 }