docster99 commited on
Commit
75582a8
·
verified ·
1 Parent(s): cbf6065

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -9,6 +9,15 @@ def load_data():
9
  # Load pre-processed data from csv file
10
  df = pd.read_csv("processed_data.csv") # replace with your dataset
11
 
 
 
 
 
 
 
 
 
 
12
  # Ensure order_time is treated as datetime for plots (important since it loses dtype during CSV save/load)
13
  if 'order_time' in df.columns:
14
  df['order_time'] = pd.to_datetime(df['order_time'])
@@ -34,6 +43,7 @@ def app():
34
  total_revenue = df['total_price'].sum()
35
  most_popular_pizza_size = df['pizza_size'].value_counts().idxmax()
36
  most_frequent_pizza_category = df['pizza_category'].value_counts().idxmax()
 
37
  total_pizzas_sold = df['quantity'].sum()
38
 
39
 
@@ -49,6 +59,7 @@ def app():
49
  st.sidebar.metric("Total Revenue", f"${total_revenue:,.2f}")
50
  st.sidebar.metric("Most Popular Pizza Size", most_popular_pizza_size )
51
  st.sidebar.metric("Most Popular Pizza Category", most_frequent_pizza_category)
 
52
  st.sidebar.metric("Total Pizzas Sold", total_pizzas_sold)
53
 
54
 
@@ -98,10 +109,16 @@ def app():
98
  # Axis and Final Display Cleanup
99
  ax.set_xlabel(" ".join(plot["x"].split("_")).title())
100
 
101
- if "y" in plot.keys() and plot["y"] != "quantity":
102
- ax.set_ylabel(" ".join(plot["y"].split("_")).title())
103
- elif plot["type"] != "count":
104
- ax.set_ylabel("Quantity")
 
 
 
 
 
 
105
 
106
  st.pyplot(fig)
107
  plt.close(fig) # Close the figure to free up memory
 
9
  # Load pre-processed data from csv file
10
  df = pd.read_csv("processed_data.csv") # replace with your dataset
11
 
12
+ # Explicitly cast metric columns to numeric types after reading from CSV
13
+ try:
14
+ df['total_price'] = df['total_price'].astype(float)
15
+ df['quantity'] = df['quantity'].astype(int)
16
+ except Exception as e:
17
+ # Fallback for logging if a type conversion fails unexpectedly
18
+ print(f"Error during type casting in app.py: {e}")
19
+
20
+
21
  # Ensure order_time is treated as datetime for plots (important since it loses dtype during CSV save/load)
22
  if 'order_time' in df.columns:
23
  df['order_time'] = pd.to_datetime(df['order_time'])
 
43
  total_revenue = df['total_price'].sum()
44
  most_popular_pizza_size = df['pizza_size'].value_counts().idxmax()
45
  most_frequent_pizza_category = df['pizza_category'].value_counts().idxmax()
46
+ most_popular_pizza_name = df['pizza_name'].value_counts().idxmax()
47
  total_pizzas_sold = df['quantity'].sum()
48
 
49
 
 
59
  st.sidebar.metric("Total Revenue", f"${total_revenue:,.2f}")
60
  st.sidebar.metric("Most Popular Pizza Size", most_popular_pizza_size )
61
  st.sidebar.metric("Most Popular Pizza Category", most_frequent_pizza_category)
62
+ st.sidebar.metric("Most Popular Pizza Name", most_popular_pizza_name)
63
  st.sidebar.metric("Total Pizzas Sold", total_pizzas_sold)
64
 
65
 
 
109
  # Axis and Final Display Cleanup
110
  ax.set_xlabel(" ".join(plot["x"].split("_")).title())
111
 
112
+ if "y" in plot.keys():
113
+ # Customize y-label for revenue plots
114
+ if plot["title"] == "Monthly Revenue Trends by Pizza Category":
115
+ ax.set_ylabel("Total Revenue (USD)")
116
+ elif plot["y"] != "quantity":
117
+ ax.set_ylabel(" ".join(plot["y"].split("_")).title())
118
+ else:
119
+ ax.set_ylabel("Quantity Sold")
120
+ elif plot["type"] == "count":
121
+ ax.set_ylabel("Order Count")
122
 
123
  st.pyplot(fig)
124
  plt.close(fig) # Close the figure to free up memory