File size: 3,442 Bytes
0a478de |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
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
# Write a code snippet to calculate key metrics from the pizza orders dataframe, including the
# total number of unique orders, total revenue generated, the most popular pizza size, the most
# frequent pizza category, total pizzas sold
total_orders = df['order_id'].drop_duplicates() #function which can calculate the number of unique values
total_revenue = df['total_price'].sum() #function which can sum the column
most_popular_size = df['pizza_size'].value_counts().idxmax() #function which can get the maximum value
most_frequent_category = df['pizza_category'].value_counts().idxmax() #function which can count of value of each product
total_pizzas_sold = df['quantity'].sum()
""""""""""""
# Sidebar with key metrics
# Write a code snippet to display key metrics in the sidebar of a Streamlit application.
# Show the total number of orders, total revenue (formatted as currency), the most popular
# pizza size, the most popular pizza category, and the total number of pizzas sold
# using the st.sidebar.metric function.
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", "y": "quantity", "top": 5}, #Write the appropriiate column as per the title given
{"title": "Quantity of Pizzas Sold by Category and Time of the Day", "x": "order_time", "hue": "pizza_category"}, #Write the appropriiate column as per the title given
{"title": "Quantity of Pizzas Sold by Size and Time of the Day", "x": "order_time", "hue": "pizza_size"}, #Write the appropriiate column as per the title given
{"title": "Monthly Revenue Trends by Pizza Category", "x": "order_date", "y": "total_price", "hue": "pizza_category", "estimator": "sum", "marker": "o"}, #Write the appropriiate column as per the title given
]
for plot in plots:
st.header(plot["title"])
fig, ax = plt.subplots()
if "Top Selling" in plot["title"]:
sns.countplot(data=df, x=plot["x"], y=plot["y"],top=plot["top"])
if "Category" in plot["title"]:
sns.countplot(data=df, x=plot["x"], hue=plot["hue"])
if "Size" in plot["title"]:
sns.countplot(data=df, x=plot["x"], hue=plot["hue"])
if "Revenue" in plot["title"]:
sns.countplot(data=df, x=plot["x"], y=plot["y"],ax=plot["top"], hue=plot["hue"], estimator=plot["estimator"], marker=plot["marker"])
else:
ax.set_ylabel("quantity")
ax.legend(bbox_to_anchor=(1,1))
st.pyplot(fig)
plt.show()
if __name__ == "__main__":
app()
|