{ "cells": [ { "cell_type": "markdown", "id": "dcb5981c", "metadata": {}, "source": [ "# Hacker News Stories 2023–2026\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `hacker_news_stories.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `hacker_news_stories.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "3e14cf6a", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"hacker_news_stories.csv\", low_memory=False, parse_dates=[\"created_at\"])\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": "93a8a3ca", "metadata": {}, "source": [ "## 4. Top domains" ] }, { "cell_type": "code", "id": "2fc1c448", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"domain\"].value_counts().head(20).to_frame(\"stories\")" ] }, { "cell_type": "markdown", "id": "723b45d5", "metadata": {}, "source": [ "## 5. Post types" ] }, { "cell_type": "code", "id": "ee3f4530", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "pd.Series({\"ask_hn\": (df[\"is_ask_hn\"] == \"true\").sum(),\n", " \"show_hn\": (df[\"is_show_hn\"] == \"true\").sum(),\n", " \"external_link\": (df[\"has_url\"] == \"true\").sum()})" ] }, { "cell_type": "markdown", "id": "2018621c", "metadata": {}, "source": [ "## 6. Points distribution" ] }, { "cell_type": "code", "id": "49a59f7e", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"points\"].dropna().clip(upper=1000).hist(bins=50, figsize=(8, 4))" ] }, { "cell_type": "markdown", "id": "fa117bb0", "metadata": {}, "source": [ "## 7. Monthly volume" ] }, { "cell_type": "code", "id": "596738e6", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(df[\"created_at\"].dt.to_period(\"M\")).size().plot(figsize=(11, 4))" ] }, { "cell_type": "markdown", "id": "4e81f56e", "metadata": {}, "source": [ "## 8. Hour of day" ] }, { "cell_type": "code", "id": "504dde7f", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.groupby(\"hour\")[\"object_id\"].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 }