SuhasGholkar commited on
Commit
451a1f2
Β·
verified Β·
1 Parent(s): 349a6ca

Update eda.py

Browse files
Files changed (1) hide show
  1. eda.py +79 -3
eda.py CHANGED
@@ -321,10 +321,10 @@ def render_eda():
321
 
322
  orders_monthly_all = data["orders_monthly"].copy()
323
  if "month" in orders_monthly_all.columns:
324
- orders_monthly_all["month"] = pd.to_datetime(orders_monthly_all["month"]).dt.floor("D")
325
 
326
  if orders_monthly_all.empty or "month" not in orders_monthly_all.columns:
327
- min_dt = max_dt = pd.Timestamp("1970-01-01").date()
328
  else:
329
  min_dt = orders_monthly_all["month"].min().date()
330
  max_dt = orders_monthly_all["month"].max().date()
@@ -549,4 +549,80 @@ def render_eda():
549
  if dataset_choice in ["All", "Products"]:
550
  show_products()
551
  if dataset_choice in ["All", "Customers"]:
552
- show_customers()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
 
322
  orders_monthly_all = data["orders_monthly"].copy()
323
  if "month" in orders_monthly_all.columns:
324
+ orders_monthly_all["month"] = pd.to_datetime(orders_monthly_all["month"], errors='coerce').dt.floor("D")
325
 
326
  if orders_monthly_all.empty or "month" not in orders_monthly_all.columns:
327
+ min_dt, max_dt = _fallback_date_bounds()
328
  else:
329
  min_dt = orders_monthly_all["month"].min().date()
330
  max_dt = orders_monthly_all["month"].max().date()
 
549
  if dataset_choice in ["All", "Products"]:
550
  show_products()
551
  if dataset_choice in ["All", "Customers"]:
552
+ show_customers()
553
+
554
+
555
+ def _fallback_date_bounds():
556
+ # Olist public dataset range
557
+ return pd.Timestamp("2016-01-01").date(), pd.Timestamp("2018-12-31").date()
558
+
559
+
560
+
561
+ def render_summary():
562
+ st.subheader("EDA Summary")
563
+ data = load_summaries()
564
+ if data is None:
565
+ st.info("No EDA data available yet.")
566
+ return
567
+
568
+ # Compute date bounds
569
+ orders_monthly_all = data.get("orders_monthly", pd.DataFrame()).copy()
570
+ if not orders_monthly_all.empty:
571
+ # Normalize string month
572
+ if "month" in orders_monthly_all.columns:
573
+ try:
574
+ orders_monthly_all["month"] = pd.to_datetime(orders_monthly_all["month"], errors='coerce').dt.floor("D")
575
+ except Exception:
576
+ pass
577
+ if orders_monthly_all.empty or "month" not in orders_monthly_all.columns:
578
+ min_dt, max_dt = _fallback_date_bounds()
579
+ orders_monthly_f = pd.DataFrame(columns=["month","count"])
580
+ else:
581
+ min_dt = orders_monthly_all["month"].min().date()
582
+ max_dt = orders_monthly_all["month"].max().date()
583
+ orders_monthly_f = orders_monthly_all.copy()
584
+
585
+ # KPIs
586
+ c1, c2, c3 = st.columns(3)
587
+ try:
588
+ ords = data.get("orders", pd.DataFrame())
589
+ total_orders = int(ords["count"].sum()) if "count" in ords.columns else None
590
+ c1.metric("Total Orders", f"{total_orders:,}" if total_orders is not None else "β€”")
591
+ except Exception:
592
+ c1.metric("Total Orders", "β€”")
593
+
594
+ try:
595
+ delivery = data.get("delivery", pd.DataFrame([{"avg_delivery_days": None}]))
596
+ avg_delivery = delivery["avg_delivery_days"].iloc[0] if "avg_delivery_days" in delivery.columns else None
597
+ c2.metric("Avg Delivery (days)", round(float(avg_delivery), 2) if avg_delivery is not None else "β€”")
598
+ except Exception:
599
+ c2.metric("Avg Delivery (days)", "β€”")
600
+
601
+ try:
602
+ rv = data.get("reviews", pd.DataFrame())
603
+ if not rv.empty and all(col in rv.columns for col in ["review_score","count"]):
604
+ avg_rev = (rv["review_score"] * rv["count"]).sum() / max(1, rv["count"].sum())
605
+ c3.metric("Avg Review", round(float(avg_rev), 2))
606
+ else:
607
+ c3.metric("Avg Review", "β€”")
608
+ except Exception:
609
+ c3.metric("Avg Review", "β€”")
610
+
611
+ st.markdown("### Orders per Month")
612
+ if not orders_monthly_f.empty:
613
+ st.line_chart(orders_monthly_f.set_index("month")["count"])
614
+ else:
615
+ st.caption(f"(No monthly series found; typical range is {min_dt} to {max_dt})")
616
+
617
+ st.markdown("### Order Status Distribution")
618
+ ords = data.get("orders", pd.DataFrame())
619
+ if not ords.empty and "order_status" in ords.columns:
620
+ st.bar_chart(ords.set_index("order_status")["count"])
621
+
622
+ st.markdown("### Top Product Categories")
623
+ cats = data.get("categories", pd.DataFrame())
624
+ if not cats.empty:
625
+ show = cats.rename(columns={"items_sold":"count"})
626
+ col = "count" if "count" in show.columns else ( "items_sold" if "items_sold" in show.columns else None )
627
+ if col:
628
+ st.bar_chart(show.set_index("product_category_name_english")[col].head(20))