File size: 4,508 Bytes
89e696a
36f3034
 
d496756
89e696a
36f3034
2c1bfb4
 
45bb8a5
f637681
 
 
 
45bb8a5
ab9c8b0
2c1bfb4
 
 
 
 
 
ab9c8b0
3a7c531
2c1bfb4
36f3034
b6148e0
ab9c8b0
 
36f3034
 
ab9c8b0
36f3034
 
 
 
 
45bb8a5
 
 
 
 
f637681
45bb8a5
 
 
f637681
 
 
 
 
45bb8a5
 
f637681
 
45bb8a5
 
 
 
 
 
 
f637681
45bb8a5
 
f637681
45bb8a5
 
 
f637681
 
 
 
 
45bb8a5
f637681
 
 
 
 
45bb8a5
 
36f3034
 
ab9c8b0
36f3034
 
 
 
 
45bb8a5
 
 
 
f637681
 
45bb8a5
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go

# Configuración de la página principal
st.set_page_config(page_title="Customer Insights App", page_icon=":bar_chart:")

# Cargar el archivo CSV que ya está disponible en la web
df = pd.read_csv("df_clean.csv")  # Asegúrate de que la ruta del archivo es correcta

# Ignorar las dos últimas columnas
df = df.iloc[:, :-2]

# Diseño de la página principal
st.title("Welcome to Customer Insights App")
st.markdown("""
    This app helps businesses analyze customer behaviors and provide personalized recommendations based on purchase history. 
    Use the tools below to dive deeper into your customer data.
""")

# Menú de navegación
page = st.selectbox("Selecciona la herramienta que quieres utilizar", ["", "Customer Analysis", "Customer Recommendations"])

# Página Home
if page == "":
    st.markdown("## Welcome to the Customer Insights App")
    st.write("Use the dropdown menu to navigate between the different sections.")

# Página Customer Analysis
elif page == "Customer Analysis":
    st.title("Customer Analysis")
    st.markdown("""
        Use the tools below to explore your customer data.
    """)

    # Input para código de cliente
    customer_code = st.text_input("Enter Customer Code")

    if customer_code:
        # Filtrar datos para el cliente seleccionado
        customer_data = df[df.iloc[:, 0] == customer_code]  # Buscar cliente en la primera columna

        if not customer_data.empty:
            st.write(f"### Analysis for Customer {customer_code}")

            # Obtener las 15 columnas con los valores más altos (ignorar la columna de cliente)
            top_15_manufacturers = customer_data.iloc[:, 1:].T.nlargest(15, customer_data.index[0])

            # Generar el spider chart con los top 15 fabricantes
            fig_spider = go.Figure()
            fig_spider.add_trace(go.Scatterpolar(
                r=top_15_manufacturers[customer_data.index[0]].values,
                theta=top_15_manufacturers.index,
                fill='toself',
                name=f'Customer {customer_code}'
            ))
            fig_spider.update_layout(
                polar=dict(
                    radialaxis=dict(
                        visible=True,
                        range=[0, top_15_manufacturers[customer_data.index[0]].max() + 1]
                    )),
                showlegend=False,
                title=f'Spider Chart for Top 15 Manufacturers of Customer {customer_code}'
            )
            st.plotly_chart(fig_spider)

            # Ventas del cliente 2021-2024 (si los datos existen)
            if 'VENTA_2021' in df.columns and 'VENTA_2022' in df.columns and 'VENTA_2023' in df.columns and 'VENTA_2024' in df.columns:
                years = ['2021', '2022', '2023', '2024']
                sales_columns = ['VENTA_2021', 'VENTA_2022', 'VENTA_2023', 'VENTA_2024']
                customer_sales = customer_data[sales_columns].values[0]

                fig_sales = px.line(x=years, y=customer_sales, markers=True, title=f'Sales Over the Years for Customer {customer_code}')
                fig_sales.update_layout(xaxis_title="Year", yaxis_title="Sales")
                st.plotly_chart(fig_sales)
            else:
                st.warning("Sales data for 2021-2024 not available.")
        else:
            st.warning(f"No data found for customer {customer_code}. Please check the code.")

# Página Customer Recommendations
elif page == "Customer Recommendations":
    st.title("Customer Recommendations")
    st.markdown("""
        Get tailored recommendations for your customers based on their purchasing history.
    """)

    # Input para código de cliente
    customer_code = st.text_input("Enter Customer Code for Recommendations")

    if customer_code:
        customer_data = df[df.iloc[:, 0] == customer_code]

        if not customer_data.empty:
            # Mostrar historial de compras del cliente seleccionado
            st.write(f"### Purchase History for Customer {customer_code}")
            st.write(customer_data)

            # Generar recomendaciones (placeholder)
            st.write(f"### Recommended Products for Customer {customer_code}")
            # Aquí puedes reemplazar con la lógica del modelo de recomendación
            st.write("Product A, Product B, Product C")
        else:
            st.warning(f"No data found for customer {customer_code}. Please check the code.")