|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "f00ac002", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "📊 E-Commerce Data Analysis & Visualization\n", |
| 9 | + "Python Practice Challenge\n", |
| 10 | + "🧠 Objective\n", |
| 11 | + "\n", |
| 12 | + "This notebook helps you practice real-world Python data analysis skills by working with a small e-commerce dataset.\n", |
| 13 | + "You will:\n", |
| 14 | + "\n", |
| 15 | + "Load and explore data\n", |
| 16 | + "\n", |
| 17 | + "Analyze trends\n", |
| 18 | + "\n", |
| 19 | + "Create meaningful visualizations\n", |
| 20 | + "\n", |
| 21 | + "Draw business insights\n", |
| 22 | + "\n", |
| 23 | + "✅ Skills Practiced\n", |
| 24 | + "\n", |
| 25 | + "Pandas (data manipulation)\n", |
| 26 | + "\n", |
| 27 | + "Matplotlib & Seaborn (visualization)\n", |
| 28 | + "\n", |
| 29 | + "Exploratory Data Analysis (EDA)\n", |
| 30 | + "\n", |
| 31 | + "Thinking like a data analyst 🎯\n", |
| 32 | + "\n", |
| 33 | + "📁 Dataset\n", |
| 34 | + "\n", |
| 35 | + "We use a sample e-commerce dataset containing:\n", |
| 36 | + "\n", |
| 37 | + "Orders\n", |
| 38 | + "\n", |
| 39 | + "Dates\n", |
| 40 | + "\n", |
| 41 | + "Categories\n", |
| 42 | + "\n", |
| 43 | + "Customers\n", |
| 44 | + "\n", |
| 45 | + "Revenue\n", |
| 46 | + "\n", |
| 47 | + "🔹 Cell 1: Import Libraries\n", |
| 48 | + "import pandas as pd\n", |
| 49 | + "import matplotlib.pyplot as plt\n", |
| 50 | + "import seaborn as sns\n", |
| 51 | + "\n", |
| 52 | + "# visualization settings\n", |
| 53 | + "sns.set(style=\"whitegrid\")\n", |
| 54 | + "plt.rcParams[\"figure.figsize\"] = (10, 5)\n", |
| 55 | + "\n", |
| 56 | + "🔹 Cell 2: Load Dataset\n", |
| 57 | + "\n", |
| 58 | + "If you're running this via Binder or locally, this path works.\n", |
| 59 | + "If using Colab, upload the CSV manually.\n", |
| 60 | + "\n", |
| 61 | + "df = pd.read_csv(\"../../public/data/ecommerce_sample.csv\")\n", |
| 62 | + "df.head()\n", |
| 63 | + "\n", |
| 64 | + "🔹 Cell 3: Basic Dataset Info\n", |
| 65 | + "df.info()\n", |
| 66 | + "\n", |
| 67 | + "df.describe()\n", |
| 68 | + "\n", |
| 69 | + "🔹 Cell 4: Datetime Conversion\n", |
| 70 | + "df['order_date'] = pd.to_datetime(df['order_date'])\n", |
| 71 | + "\n", |
| 72 | + "df.dtypes\n", |
| 73 | + "\n", |
| 74 | + "\n", |
| 75 | + "✅ This allows time-based analysis.\n", |
| 76 | + "\n", |
| 77 | + "🔹 Cell 5: Monthly Revenue Trend\n", |
| 78 | + "\n", |
| 79 | + "📈 Question: How does revenue change over time?\n", |
| 80 | + "\n", |
| 81 | + "monthly_revenue = (\n", |
| 82 | + " df\n", |
| 83 | + " .groupby(df['order_date'].dt.to_period('M'))['revenue']\n", |
| 84 | + " .sum()\n", |
| 85 | + ")\n", |
| 86 | + "\n", |
| 87 | + "monthly_revenue.plot(\n", |
| 88 | + " kind='line',\n", |
| 89 | + " marker='o',\n", |
| 90 | + " title='Monthly Revenue Trend'\n", |
| 91 | + ")\n", |
| 92 | + "\n", |
| 93 | + "plt.xlabel(\"Month\")\n", |
| 94 | + "plt.ylabel(\"Total Revenue\")\n", |
| 95 | + "plt.show()\n", |
| 96 | + "\n", |
| 97 | + "✅ Insight\n", |
| 98 | + "\n", |
| 99 | + "Identify peak sales months\n", |
| 100 | + "\n", |
| 101 | + "Observe growth or decline trends\n", |
| 102 | + "\n", |
| 103 | + "🔹 Cell 6: Revenue by Category\n", |
| 104 | + "\n", |
| 105 | + "📊 Question: Which product category generates the most revenue?\n", |
| 106 | + "\n", |
| 107 | + "category_sales = (\n", |
| 108 | + " df.groupby('category')['revenue']\n", |
| 109 | + " .sum()\n", |
| 110 | + " .sort_values(ascending=False)\n", |
| 111 | + ")\n", |
| 112 | + "\n", |
| 113 | + "sns.barplot(\n", |
| 114 | + " x=category_sales.index,\n", |
| 115 | + " y=category_sales.values\n", |
| 116 | + ")\n", |
| 117 | + "plt.title(\"Revenue by Product Category\")\n", |
| 118 | + "plt.xlabel(\"Category\")\n", |
| 119 | + "plt.ylabel(\"Revenue\")\n", |
| 120 | + "plt.show()\n", |
| 121 | + "\n", |
| 122 | + "✅ Insight\n", |
| 123 | + "\n", |
| 124 | + "Focus marketing on top-performing categories\n", |
| 125 | + "\n", |
| 126 | + "Spot underperforming ones\n", |
| 127 | + "\n", |
| 128 | + "🔹 Cell 7: Top Customers\n", |
| 129 | + "\n", |
| 130 | + "👥 Question: Who are the highest-value customers?\n", |
| 131 | + "\n", |
| 132 | + "customer_sales = (\n", |
| 133 | + " df.groupby('customer')['revenue']\n", |
| 134 | + " .sum()\n", |
| 135 | + " .sort_values(ascending=False)\n", |
| 136 | + ")\n", |
| 137 | + "\n", |
| 138 | + "customer_sales\n", |
| 139 | + "\n", |
| 140 | + "🔹 Cell 8: Customer Revenue Share (Pie Chart)\n", |
| 141 | + "customer_sales.plot(\n", |
| 142 | + " kind='pie',\n", |
| 143 | + " autopct='%1.1f%%',\n", |
| 144 | + " title='Revenue Contribution by Customer'\n", |
| 145 | + ")\n", |
| 146 | + "\n", |
| 147 | + "plt.ylabel('')\n", |
| 148 | + "plt.show()\n", |
| 149 | + "\n", |
| 150 | + "✅ Insight\n", |
| 151 | + "\n", |
| 152 | + "A few customers often drive most revenue\n", |
| 153 | + "\n", |
| 154 | + "Useful for loyalty programs\n", |
| 155 | + "\n", |
| 156 | + "🔹 Cell 9: Order Value Distribution\n", |
| 157 | + "\n", |
| 158 | + "📉 Question: What does individual order value look like?\n", |
| 159 | + "\n", |
| 160 | + "sns.histplot(df['revenue'], bins=10, kde=True)\n", |
| 161 | + "plt.title(\"Order Value Distribution\")\n", |
| 162 | + "plt.xlabel(\"Order Revenue\")\n", |
| 163 | + "plt.ylabel(\"Frequency\")\n", |
| 164 | + "plt.show()\n", |
| 165 | + "\n", |
| 166 | + "✅ Insight\n", |
| 167 | + "\n", |
| 168 | + "Helps detect low/high-value orders\n", |
| 169 | + "\n", |
| 170 | + "Useful for pricing strategy\n", |
| 171 | + "\n", |
| 172 | + "🔹 Cell 10: Key Business Insights (Markdown Cell)\n", |
| 173 | + "## 📌 Key Insights\n", |
| 174 | + "\n", |
| 175 | + "- Electronics is the highest revenue-generating category\n", |
| 176 | + "- Revenue peaks in later months, indicating growth\n", |
| 177 | + "- A small number of customers contribute a large share of revenue\n", |
| 178 | + "- Most orders cluster around mid-range prices\n", |
| 179 | + "\n", |
| 180 | + "These insights can help improve:\n", |
| 181 | + "- Inventory planning\n", |
| 182 | + "- Marketing campaigns\n", |
| 183 | + "- Customer retention strategies\n", |
| 184 | + "\n", |
| 185 | + "🎯 Challenge Tasks (For Learners)\n", |
| 186 | + "## ✅ Try This Yourself\n", |
| 187 | + "\n", |
| 188 | + "1. Find the **best-selling product**\n", |
| 189 | + "2. Calculate **average order value**\n", |
| 190 | + "3. Identify **repeat customers**\n", |
| 191 | + "4. Create a **daily sales trend**\n", |
| 192 | + "5. Add a new visualization of your choice\n", |
| 193 | + "\n", |
| 194 | + "💡 Bonus: Turn this into a Streamlit dashboard!\n", |
| 195 | + "\n", |
| 196 | + "🚀 Next Steps\n", |
| 197 | + "\n", |
| 198 | + "Extend analysis with more data\n", |
| 199 | + "\n", |
| 200 | + "Add ML models (forecasting, clustering)\n", |
| 201 | + "\n", |
| 202 | + "Build dashboards (Streamlit)" |
| 203 | + ] |
| 204 | + } |
| 205 | + ], |
| 206 | + "metadata": { |
| 207 | + "language_info": { |
| 208 | + "name": "python" |
| 209 | + } |
| 210 | + }, |
| 211 | + "nbformat": 4, |
| 212 | + "nbformat_minor": 5 |
| 213 | +} |
0 commit comments