RDA9527 commited on
Commit
a6a7246
·
verified ·
1 Parent(s): b42a232

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +63 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import seaborn as sns
3
+ import matplotlib.pyplot as plt
4
+ import pandas as pd
5
+
6
+ # Load data
7
+ def load_data():
8
+ df = pd.read_csv("processed_data.csv") # replace with your dataset
9
+ return df
10
+
11
+ # Create Streamlit app
12
+ def app():
13
+ # Title for the app
14
+ st.title("Pizza Sales Data Analysis Dashboard")
15
+ df = load_data()
16
+
17
+ df = pd.DataFrame(df)
18
+
19
+ # Calculate key metrics
20
+ total_orders = df['order_id'].nunique()
21
+ total_revenue = df['total_price'].sum()
22
+ most_popular_size = df['pizza_size'].value_counts().idxmax()
23
+ most_frequent_category = df['pizza_category'].value_counts().idxmax()
24
+ total_pizzas_sold = df['quantity'].sum()
25
+ repeat_customers = df.groupby('order_id').size().value_counts().get(2, 0)
26
+
27
+ # Sidebar with key metrics
28
+ st.sidebar.header("Key Metrics")
29
+ st.sidebar.metric("Total Orders", total_orders)
30
+ st.sidebar.metric("Total Revenue", f"${total_revenue:,.2f}")
31
+ st.sidebar.metric("Most Popular Size", most_popular_size)
32
+ st.sidebar.metric("Most Popular Category", most_frequent_category)
33
+ st.sidebar.metric("Total Pizzas Sold", total_pizzas_sold)
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
+
62
+ if __name__ == "__main__":
63
+ app()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ pandas==1.5.2
2
+ matplotlib==3.6.2
3
+ seaborn==0.12.1
4
+ scipy==1.10.0
5
+ numpy==1.23.5