{ "cells": [ { "cell_type": "markdown", "id": "7ba93c6f", "metadata": {}, "source": [ "# Magic: The Gathering Card Catalogue\n", "\n", "Starter notebook for the Kaggle dataset in this folder. It loads `mtg_cards.csv` with pandas and walks through quality checks and a first piece of analysis.\n", "\n", "**Files:** `mtg_cards.csv`, `data_dictionary.csv`." ] }, { "cell_type": "markdown", "id": "0000f7f2", "metadata": {}, "source": [ "## 1. Load the data" ] }, { "cell_type": "code", "id": "8bb2f2bc", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv(\"mtg_cards.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": "d6a74d87", "metadata": {}, "source": [ "## 4. Rarity mix" ] }, { "cell_type": "code", "id": "382aeeb3", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"rarity\"].value_counts().to_frame(\"cards\")" ] }, { "cell_type": "markdown", "id": "bb9801b6", "metadata": {}, "source": [ "## 5. Card types" ] }, { "cell_type": "code", "id": "b720a0bd", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "for c in [\"is_creature\", \"is_land\", \"is_instant\", \"is_sorcery\", \"is_artifact\", \"is_enchantment\", \"is_planeswalker\"]:\n", " print(c, int((df[c].astype(str).str.lower() == \"true\").sum()))" ] }, { "cell_type": "markdown", "id": "f7dd32b3", "metadata": {}, "source": [ "## 6. Mana cost distribution" ] }, { "cell_type": "code", "id": "ee71283f", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"cmc\"].dropna().clip(upper=12).value_counts().sort_index().plot(kind=\"bar\", figsize=(9, 4))" ] }, { "cell_type": "markdown", "id": "2dec8235", "metadata": {}, "source": [ "## 7. Price by rarity" ] }, { "cell_type": "code", "id": "ef392cd4", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df.boxplot(column=\"price_usd\", by=\"rarity\", figsize=(9, 4))" ] }, { "cell_type": "markdown", "id": "97f1125f", "metadata": {}, "source": [ "## 8. Colours" ] }, { "cell_type": "code", "id": "5f73d685", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "df[\"color_identity\"].fillna(\"C\").value_counts().head(12).to_frame(\"cards\")" ] }, { "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 }