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() total_revenue = df['total_price'].sum() most_popular_pizza_size = df['pizza_size'].value_counts().idxmax() most_frequent_pizza_category = df['pizza_category'].value_counts().idxmax() total_pizzas_sold = df['pizza_id'].nunique() # Sidebar with key metrics st.sidebar.header('Key Metrics') st.sidebar.metric('Total Orders', total_orders) st.sidebar.metric('Total Pizzas Sold', total_pizzas_sold) st.sidebar.metric('Total Revenue', f'${total_revenue:,.2f}') st.sidebar.metric('Most Popular Pizza Size', most_popular_pizza_size) st.sidebar.metric('Most Frequent Pizza Category', most_frequent_pizza_category) # Provide the details of the plots here plots = [ {"title": "Total Pizzas Sold by Pizza Size and Categories", "x": "pizza_size", "hue": "pizza_category"}, {"title": "Monthly Revenue Trends by Pizza Size", "x": "order_month", "y": "total_revenue", "hue": "pizza_size", "estimator": "sum", "marker": "o"}, {"title": "Monthly Revenue Trends by Pizza Category", "x": "order_month", "y": "total_revenue", "hue": "pizza_category", "estimator": "sum", "marker": "o"}, {"title": "Total Revenue by Pizza Category", "x": "pizza_category", "y": "total_revenue", "estimator": "sum"}, ] for plot in plots: st.header(plot["title"]) fig, ax = plt.subplots() if "Total Pizzas Sold" in plot["title"] and "y" in plot: data_aux = df.groupby(plot["x"])[plot["y"]].sum().reset_index().sort_values(by=plot["y"], ascending=False).head(plot["top"]) ax.bar(data_aux[plot["x"]].values.tolist(), data_aux[plot["y"]].values.tolist()) if "Pizza Size" in plot["title"]: sns.countplot(data=df, x=plot["x"], hue=plot["hue"], ax=ax) if "Pizza Category" in plot["title"]: sns.lineplot(data=df, x=plot["x"], y=plot["y"], hue=plot["hue"], estimator=plot["estimator"], errorbar=None, marker=plot["marker"], ax=ax) 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") ax.legend(bbox_to_anchor=(1,1)) st.pyplot(fig) plt.show() if __name__ == "__main__": app()