Rusty52/PizzaAnalysis3
0
1import streamlit as st2import seaborn as sns3import matplotlib.pyplot as plt4import pandas as pd5 6# Load data7def load_data():8 df = pd.read_csv("processed_data.csv") # replace with your dataset9 return df10 11# Create Streamlit app12def app():13 # Title for the app14 st.title("Pizza Sales Data Analysis Dashboard")15 df = load_data()16 17 df = pd.DataFrame(df)18 19 # Calculate key metrics20 total_orders = df['order_id'].nunique() #Write the appropriate function which can calculate the number of unique values21 total_revenue = df['total_price'].sum() #Write a appropriate function which can sum the column22 most_popular_size = df['pizza_size'].value_counts().idxmax() #Write a appropriate function which can get the maximum value 23 most_frequent_category = df['pizza_category'].value_counts().idxmax() #Write a appropriate function which can count of value of each product24 total_pizzas_sold = df['quantity'].sum()25 26 # Sidebar with key metrics27 st.sidebar.header("Key Metrics")28 st.sidebar.metric("Total Orders", total_orders)29 st.sidebar.metric("Total Revenue", f"${total_revenue:,.2f}")30 st.sidebar.metric("Most Popular Size", most_popular_size)31 st.sidebar.metric("Most Popular Category", most_frequent_category)32 st.sidebar.metric("Total Pizzas Sold", total_pizzas_sold)33 34 plots = [35 {"title": "Top Selling Pizzas (by Quantity)", "x": "pizza_name", "y": "quantity", "top": 5}, #Write the appropriiate column as per the title given36 {"title": "Quantity of Pizzas Sold by Category and Time of the Day", "x": "time_of_day", "hue": "pizza_category"}, #Write the appropriiate column as per the title given37 {"title": "Quantity of Pizzas Sold by Size and Time of the Day", "x": "time_of_day", "hue": "pizza_size"}, #Write the appropriiate column as per the title given38 {"title": "Monthly Revenue Trends by Pizza Category", "x": "order_month", "y": "total_price", "hue": "pizza_category", "estimator": "sum", "marker": "o"}, #Write the appropriiate column as per the title given39 ]40 41 for plot in plots:42 st.header(plot["title"])43 44 fig, ax = plt.subplots()45 46 if "Top Selling Pizzas" in plot["title"]:47 data_aux = df.groupby(plot["x"])[plot["y"]].sum().reset_index().sort_values(by=plot["y"], ascending=False).head(plot["top"])48 ax.bar(data_aux[plot["x"]].values.tolist(), data_aux[plot["y"]].values.tolist())49 50 if "Quantity of Pizzas" in plot["title"]:51 sns.countplot(data=df, x=plot["x"], hue=plot["hue"], ax=ax)52 53 if "Monthly Revenue" in plot["title"]:54 sns.lineplot(data=df, x=plot["x"], y=plot["y"], hue=plot["hue"], estimator=plot["estimator"], errorbar=None, marker=plot["marker"], ax=ax)55 56 ax.set_xlabel(" ".join(plot["x"].split("_")).capitalize())57 if "y" in plot.keys():58 ax.set_ylabel(" ".join(plot["y"].split("_")).capitalize())59 else:60 ax.set_ylabel("Quantity")61 ax.legend(bbox_to_anchor=(1,1))62 63 st.pyplot(fig)64 65 66if __name__ == "__main__":67 app()68 