1. Why Bar Charts?
Bars compare categories after aggregation. On large tables (e.g. 5,000 rows), group first so a few bars represent totals by product line, region, etc.—not one bar per row.
2. Simple Bar Chart
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv("ecommerce_orders.csv")
category_revenue = df.groupby("Product Category")["Revenue"].sum()
fig, ax = plt.subplots(figsize=(8, 5))
ax.bar(category_revenue.index, category_revenue.values)
ax.set_title("Total Revenue by Product Category")
ax.set_xlabel("Product Category")
ax.set_ylabel("Revenue ($)")
plt.show()
Thousands of rows collapse into one bar per category (e.g. Electronics highest in a sample).
3. Grouped Bars (.unstack())
grouped = df.groupby(["Product Category", "Region"])["Revenue"].sum()
unstacked = grouped.unstack()
unstacked.plot(kind="bar", figsize=(10, 4))
plt.title("Revenue by Category Across Regions")
plt.xlabel("Product Category")
plt.ylabel("Revenue ($)")
plt.show()
.unstack() pivots the inner index (Region) into columns so each category shows side-by-side regional bars and a legend.
4. Stacked Bars
unstacked.plot(kind="bar", stacked=True, figsize=(10, 5))
plt.title("Stacked Revenue by Category and Region")
plt.xlabel("Product Category")
plt.ylabel("Total Accumulated Revenue ($)")
plt.show()
Stacking shows category total (bar height) and each region’s share within that total. Grouped bars are better for direct region-to-region comparison; stacked bars emphasize composition.