E-commerce Sales Analysis
Given an e-commerce orders dataset, answer:
- Overall revenue and order trends
- Top products / categories
- Average order value (AOV)
- Revenue by segment (city, category)
Analysis pipeline
Section titled “Analysis pipeline”flowchart LR A["Raw orders
(CSV)"] --> B["Clean
(parse dates, revenue = qty * price)"] B --> C["KPIs
(orders, AOV)"] C --> D["Visualize
(monthly trend, top products)"] D --> E["Conclude
(main revenue drivers)"]
Example columns
Section titled “Example columns”order_id,order_date,customer_idproduct,category,qty,pricecity,status
Step 1: Load and basic prep
Section titled “Step 1: Load and basic prep”import pandas as pd
df = pd.read_csv("data/orders.csv")
df["order_date"] = pd.to_datetime(df["order_date"], errors="coerce")
df["revenue"] = df["qty"] * df["price"]
print(df.shape)
print(df.head())Step 2: KPIs
Section titled “Step 2: KPIs”orders = df["order_id"].nunique()
customers = df["customer_id"].nunique()
revenue = df["revenue"].sum()
aov = revenue / orders
print("orders:", orders)
print("customers:", customers)
print("revenue:", revenue)
print("aov:", aov)Step 3: Revenue trend
Section titled “Step 3: Revenue trend”import matplotlib.pyplot as plt
monthly = (
df.dropna(subset=["order_date"])
.groupby(df["order_date"].dt.to_period("M"))
.agg(revenue=("revenue", "sum"), orders=("order_id", "nunique"))
.reset_index()
)
monthly["order_date"] = monthly["order_date"].astype(str)
plt.figure(figsize=(10, 4))
plt.plot(monthly["order_date"], monthly["revenue"], marker="o")
plt.title("Monthly revenue")
plt.xticks(rotation=30)
plt.tight_layout()
plt.show()Step 4: Top products
Section titled “Step 4: Top products”import seaborn as sns
import matplotlib.pyplot as plt
top = (
df.groupby("product")
.agg(revenue=("revenue", "sum"))
.sort_values("revenue", ascending=False)
.head(10)
.reset_index()
)
plt.figure(figsize=(10, 4))
sns.barplot(data=top, x="revenue", y="product")
plt.title("Top 10 products by revenue")
plt.tight_layout()
plt.show()Visualize it
Section titled “Visualize it”Deliverable
Section titled “Deliverable”Summarize:
- Revenue trend (up/down)
- Main revenue drivers (top products/categories)
- Any anomalies (returns, cancellations)
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Compute revenue per order
Section titled “Exercise 1 – Compute revenue per order”Exercise 2 – Average order value (AOV)
Section titled “Exercise 2 – Average order value (AOV)”Exercise 3 – Top products by revenue
Section titled “Exercise 3 – Top products by revenue”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading