|
import streamlit as st |
|
import seaborn as sns |
|
import matplotlib.pyplot as plt |
|
import pandas as pd |
|
|
|
|
|
def load_data(): |
|
df = pd.read_csv("processed_data.csv") |
|
return df |
|
|
|
|
|
def app(): |
|
|
|
st.title("Retail Data Insights Dashboard") |
|
|
|
|
|
df = load_data() |
|
|
|
|
|
total_orders = df['Transaction ID'].nunique() |
|
total_products_sold = df['Quantity'].sum() |
|
total_revenue = df['Total Amount'].sum() |
|
most_popular_product_cat = df['Product Category'].value_counts().idxmax() |
|
most_frequent_age_cat = df['Age Category'].value_counts().idxmax() |
|
|
|
|
|
st.sidebar.header("Key Metrics") |
|
st.sidebar.metric("Total Orders", total_orders) |
|
st.sidebar.metric("Total Products Sold", total_products_sold) |
|
st.sidebar.metric("Total Revenue", f"${total_revenue:,.2f}") |
|
st.sidebar.metric("Most Popular Product Category", most_popular_product_cat) |
|
st.sidebar.metric("Most Frequent Age Category", most_frequent_age_cat) |
|
|
|
|
|
plots = [ |
|
{"title": "Total Products Sold by Product and Age Categories", "x": "Product Category", "hue": "Age Category"}, |
|
{"title": "Monthly Revenue Trends by Product Category", "x": "month", "y": "Total Amount", "hue": "Product Category", "estimator": "sum", "marker": "o"}, |
|
{"title": "Monthly Revenue Trends by Age Category", "x": "month", "y": "Total Amount", "hue": "Age Category", "estimator": "sum", "marker": "o"}, |
|
{"title": "Revenue by Product Category", "x": "Product Category", "y": "Total Amount", "estimator": "sum"}, |
|
] |
|
|
|
for plot in plots: |
|
st.header(plot["title"]) |
|
|
|
fig, ax = plt.subplots() |
|
|
|
if "Total Products" in plot["title"]: |
|
sns.countplot(data=df, x=plot["x"], hue=plot["hue"], ax=ax) |
|
|
|
if "Monthly Revenue" 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) |
|
|
|
if "Revenue by Product" in plot["title"]: |
|
sns.barplot(data=df, x=plot["x"], y=plot["y"], estimator=plot["estimator"], errorbar=None, 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() |
|
|