RDA9527 commited on
Commit
1bafc48
·
verified ·
1 Parent(s): 92071d7

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -34,28 +34,30 @@ def app():
34
  st.sidebar.metric("Repeat Customers", repeat_customers)
35
 
36
  plots = [
37
- {"title": "Top-Selling Pizzas (by Quantity)", "x": "pizza_name", "y": "quantity", "top": 5},
38
- {"title": "Revenue by Pizza Category", "x": "pizza_category", "y": "total_price", "hue": "pizza_size"},
39
- {"title": "Peak Order Times (by Hour)", "x": "order_time", "y": "quantity", "agg": "value_counts", "extract_hour": True},
40
- {"title": "Monthly Revenue", "x": "order_month", "y": "total_price"}
41
  ]
42
 
43
  for plot in plots:
44
  st.header(plot["title"])
45
- if "agg" in plot:
46
- data = getattr(df[plot["x"]], plot["agg"])().sort_values(ascending=False)
47
- else:
48
- data = df.groupby(plot["x"])[plot["y"]].sum().sort_values(ascending=False)
49
- if "top" in plot:
50
- data = data.head(plot["top"])
51
  fig, ax = plt.subplots()
52
- if plot["title"] == "Revenue by Pizza Category":
53
- sns.barplot(x=plot["x"], y=plot["y"], hue=plot["hue"], data=data, ax=ax)
54
- ax.bar(data.index, data.values)
 
 
 
 
 
 
 
 
55
  ax.set_xlabel(plot["x"].capitalize())
56
  ax.set_ylabel(plot["y"].capitalize())
57
- if plot["title"] == "Monthly Revenue":
58
- ax.set_xlabel("Month")
59
  st.pyplot(fig)
60
 
61
 
 
34
  st.sidebar.metric("Repeat Customers", repeat_customers)
35
 
36
  plots = [
37
+ {"title": "Top Selling Pizzas (by Quantity)", "x": "pizza_name", "y": "quantity", "top": 5},
38
+ {"title": "Quantity of Pizzas Sold by Category and Time of the Day", "x": "time_of_day", "hue": "pizza_category"},
39
+ {"title": "Quantity of Pizzas Sold by Size and Time of the Day", "x": "time_of_day", "hue": "pizza_size"},
40
+ {"title": "Monthly Revenue Trends by Pizza Category", "x": "order_month", "y": "total_price", "hue": "pizza_category", "estimator": "sum", "marker": "o"},
41
  ]
42
 
43
  for plot in plots:
44
  st.header(plot["title"])
45
+
 
 
 
 
 
46
  fig, ax = plt.subplots()
47
+
48
+ if "top" in plot["title"]:
49
+ data = df.groupby(plot["x"]).quantity.sum().reset_index().sort_values(by="quantity", ascending=False).head()
50
+ sns.countplot(x=plot["x"], data=data, ax=ax)
51
+
52
+ if "Quantity" in plot["title"]:
53
+ sns.countplot(x=plot["x"], hue=plot["hue"], data=df, ax=ax)
54
+
55
+ if "Revenue" in plot["title"]:
56
+ sns.lineplot(x=plot["x"], y=plot["y"], hue=plot["hue"], data=df, estimator=plot["estimator"], marker=plot["marker"], ax=ax)
57
+
58
  ax.set_xlabel(plot["x"].capitalize())
59
  ax.set_ylabel(plot["y"].capitalize())
60
+
 
61
  st.pyplot(fig)
62
 
63