import streamlit as st import seaborn as sns import matplotlib.pyplot as plt import pandas as pd # Load data def load_data(): df = pd.read_csv("processed_data.csv") # replace with your dataset return df # Create Streamlit app def app(): # Title for the app st.title("Pizza Sales Data Analysis Dashboard") df = load_data() df = pd.DataFrame(df) # Calculate key metrics total_orders = df['order_id'].nunique() # number of unique orders total_revenue = df['total_price'].sum() # total revenue from orders most_popular_size = df['pizza_size'].value_counts().idxmax() # pizza size with highest frequency most_frequent_category = df['pizza_category'].value_counts().idxmax() # pizza category with highest frequency total_pizzas_sold = df['quantity'].sum() # Total quantity of pizza Sold # Sidebar with key metrics st.sidebar.header("Key Metrics") st.sidebar.metric("Total Orders", total_orders) st.sidebar.metric("Total Revenue", f"${total_revenue:,.2f}") st.sidebar.metric("Most Popular Size", most_popular_size) st.sidebar.metric("Most Popular Category", most_frequent_category) st.sidebar.metric("Total Pizzas Sold", total_pizzas_sold) # Provide the details of the plots here plots = [ {"title": "Top Selling Pizzas (by Quantity)", "x": "pizza_name_id", "y": "quantity", "top": 5}, {"title": "Quantity of Pizzas Sold by Category and Time of the Day","x": "pizza_category", "y": "quantity" , "hue": "time_of_day" , "estimator": "sum"}, {"title": "Quantity of Pizzas Sold by Size and Time of the Day","x": "pizza_size", "y": "quantity" , "hue": "time_of_day" , "estimator": "sum"}, {"title": "Monthly Revenue Trends by Pizza Category", "x": "order_month", "y": "total_price", "hue": "pizza_category", "estimator": "sum", "style": "pizza_category"}, ] for plot in plots: st.header(plot["title"]) fig, ax = plt.subplots() if "Top Selling Pizzas" in plot["title"]: data_aux= df.groupby(plot["x"])[plot["y"]].sum().reset_index().sort_values(by=plot["y"],ascending=False).head(plot["top"]) sns.barplot(data=data_aux, x=plot["x"], y=plot["y"], errorbar=None , order=data_aux[plot["x"]] , ax=ax) plt.xticks(rotation=45) plt.tight_layout() # Adjust spacing so labels fit if "Quantity of Pizzas" in plot["title"]: sns.barplot(data=df, x=plot["x"], y=plot["y"], hue=plot["hue"], estimator=plot["estimator"], errorbar=None , ax=ax) if "Monthly Revenue" in plot["title"]: sns.lineplot(data=df, x=plot["x"], y=plot["y"], hue=plot["hue"], estimator=plot["estimator"] , style=plot["style"] , errorbar=None, markers=True , ax=ax) plt.xticks(rotation=90); ax.set_xlabel(" ".join(plot["x"].split("_")).capitalize()) if "y" in plot.keys(): ax.set_ylabel(" ".join(plot["y"].split("_")).capitalize()) else: ax.set_ylabel("Quantity") if plot.get("hue"): ax.legend(bbox_to_anchor=(1, 1)) st.pyplot(fig) if __name__ == "__main__": app()