File size: 2,575 Bytes
0618ce0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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("Retail Data Insights Dashboard")

    # Load data
    df = load_data()

    # Key Metrics from the 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()

    # Display metrics in the sidebar
    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()