Lesson 6 — Intermediate

Sales EDA Project — Data se Insight tak

Ab tak sab tools seekhe — ab ek asli dataset. Is project me hum sales data ko load se lekar insight tak le jaayenge: clean karo, har column explore karo, graphs banao, aur aise findings nikaalo jo business ko paise bachaa dein.

⏱ 35 min• Intermediate• Jupyter / Colab

Project kya karega?

WHAT

Ek 5-column sales CSV (date, city, category, qty, amount) par complete EDA: load → sanity checks → missing/duplicate fix → univariate → bivariate → group summaries → charts → 3 actionable insights report.

WHEN

Koi bhi naya dataset aaye — client data, internship assignment, Kaggle competition. EDA sabse pehla paid deliverable hota hai data analyst me.

WHERE

Interview me "ye CSV uthao aur batao kya dikhta hai" wala round isi skill par chalta hai. Portfolio me EDA notebook GitHub pe = proof ki data samajhna aata hai.

EDA mantra: Pehle questions banao ("Kaunse city sabse kam kama rahe hain?"), phir data se answer dhundo. Graph banana target nahi, decision badalna target hai.

Step 1 — Load + sanity check

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

BG = "#0d0d1c"
plt.rcParams.update({"figure.facecolor": BG, "axes.facecolor": BG,
    "axes.labelcolor": "#8a8aa3", "text.color": "white",
    "xtick.color": "#8a8aa3", "ytick.color": "#8a8aa3"})

df = pd.read_csv("sales.csv", parse_dates=["date"])

print(df.shape)            # rows x cols
print(df.head())
print(df.info())           # types + nulls
print(df.isna().sum())     # missing per column
print(df.duplicated().sum())   # duplicates
print(df.describe(include="all"))   # numeric + category summary

# Sanity: kya dates range me hain? amount >= 0?
print(df["date"].min(), df["date"].max())
print((df["amount"] < 0).sum())    # negative amounts = data error

Step 2 — Clean

# 1. Duplicates
df = df.drop_duplicates()

# 2. Missing
df["city"] = df["city"].fillna("Unknown")
df = df.dropna(subset=["amount"])     # amount hi nahi to row bekaar

# 3. Types
df["date"] = pd.to_datetime(df["date"])
df["amount"] = pd.to_numeric(df["amount"], errors="coerce")

# 4. Derived columns (analysis ke liye)
df["month"] = df["date"].dt.to_period("M").astype(str)
df["weekday"] = df["date"].dt.day_name()
df["unit_price"] = df["amount"] / df["qty"].replace(0, np.nan)

print("clean shape:", df.shape)
print(df.isna().sum().sum(), "total nulls left")

Step 3 — Univariate (har column akele)

# Numeric: distribution
fig, axes = plt.subplots(1, 2, figsize=(12, 4.5))
df["amount"].hist(bins=40, ax=axes[0], color="#2dd4bf")
axes[0].set_title("Amount distribution", color="white")
df.groupby("city")["amount"].sum().sort_values().plot(
    kind="barh", ax=axes[1], color="#f0a500")
axes[1].set_title("City-wise total", color="white")
plt.tight_layout(); plt.show()

# Category: counts + share
print(df["category"].value_counts(normalize=True).round(3))

# Outliers: IQR method
q1, q3 = df["amount"].quantile([.25, .75])
iqr = q3 - q1
out = df[(df["amount"] < q1 - 1.5*iqr) | (df["amount"] > q3 + 1.5*iqr)]
print("outlier rows:", len(out))
Two panel exploratory analysis dashboard with trend and category charts on dark background
EDA dashboard — monthly trend + category summary (do panel me)

Step 4 — Bivariate + group insights

# Month-wise trend (kya business badh raha hai?)
trend = df.groupby("month")["amount"].sum()
trend.plot(kind="line", marker="o", color="#f0a500", figsize=(10, 4))
plt.title("Monthly Revenue Trend", color="white")
plt.xticks(rotation=45); plt.tight_layout(); plt.show()

# Category x City heatmap
pt = df.pivot_table(index="city", columns="category",
                    values="amount", aggfunc="sum", fill_value=0)
sns.heatmap(pt, annot=True, fmt=".0f", cmap="viridis")
plt.title("City x Category Revenue", color="white")
plt.show()

# Top drivers
print(df.groupby("category")["amount"].agg(["sum", "mean", "count"])
        .sort_values("sum", ascending=False))

# Weekday effect
print(df.groupby("weekday")["amount"].mean().sort_values(ascending=False))

Step 5 — Insights likho (yahi asli kaam hai)

# Template - har insight: Finding + Evidence + Action
"""
INSIGHT 1 - Trend
Finding:  Revenue Jun se Oct tak lagatar upar (CAGR ~7%/month).
Evidence: month-wise sum, line chart.
Action:   Q4 stock aur staff pehle se ready rakho.

INSIGHT 2 - Concentration
Finding:  Top 2 cities = 62% revenue; bottom 3 = 8% only.
Evidence: city-wise sum (bar + share %).
Action:   Bottom cities me ya to marketing budget do ya
          operations consolidate karo.

INSIGHT 3 - Category margin proxy
Finding:  Electronics ka avg order value 3.4x Grocery ka,
          lekin order count sabse kam.
Evidence: category agg (sum/mean/count).
Action:   Electronics pe bundle offers (AOV already high),
          Grocery pe frequency campaigns (repeat chahiye).
"""
Rule of 3: EDA report me kam se kam 3 insights, har ek ka saath evidence (number + chart) aur ek recommended action. Sirf "ye badh raha hai, wo gir raha hai" = observation; action ke saath = insight.

Exercise

Question: Missing values count karne ka pandas method? (4 letters)

Question: Dataset ka (rows, columns) size batane ka attribute? (5 letters)

Common mistakes

Interview question: "EDA karte waqt sabse pehle kya dekhte ho?" — Shape, dtypes, nulls, duplicates, date range, numeric summary. Ye 6-point sanity checklist bolo to interviewer ko pata chal jaata hai ki tum procedure se kaam karte ho, guess se nahi.
Lesson complete?

Course complete! NumPy, Pandas, graphs aur EDA — sab aa gaya. Ab sales EDA project ko GitHub pe publish karo aur portfolio link resume me daalo.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course