Spaces:
Sleeping
Sleeping
GMARTINEZMILLA
commited on
Commit
•
f637681
1
Parent(s):
6012e5e
feat: generated files
Browse files- app.py +26 -22
- df_clean.csv +0 -0
- info.csv +0 -0
app.py
CHANGED
@@ -7,8 +7,10 @@ import plotly.graph_objects as go
|
|
7 |
st.set_page_config(page_title="Customer Insights App", page_icon=":bar_chart:")
|
8 |
|
9 |
# Cargar el archivo CSV que ya está disponible en la web
|
10 |
-
# Asegúrate de que
|
11 |
-
|
|
|
|
|
12 |
|
13 |
# Diseño de la página principal
|
14 |
st.title("Welcome to Customer Insights App")
|
@@ -37,19 +39,19 @@ elif page == "Customer Analysis":
|
|
37 |
|
38 |
if customer_code:
|
39 |
# Filtrar datos para el cliente seleccionado
|
40 |
-
customer_data = df[df[
|
41 |
|
42 |
if not customer_data.empty:
|
43 |
st.write(f"### Analysis for Customer {customer_code}")
|
44 |
-
|
45 |
-
#
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
fig_spider = go.Figure()
|
50 |
fig_spider.add_trace(go.Scatterpolar(
|
51 |
-
r=
|
52 |
-
theta=
|
53 |
fill='toself',
|
54 |
name=f'Customer {customer_code}'
|
55 |
))
|
@@ -57,22 +59,24 @@ elif page == "Customer Analysis":
|
|
57 |
polar=dict(
|
58 |
radialaxis=dict(
|
59 |
visible=True,
|
60 |
-
range=[0, max(
|
61 |
)),
|
62 |
showlegend=False,
|
63 |
-
title=f'Spider Chart for Customer {customer_code}'
|
64 |
)
|
65 |
st.plotly_chart(fig_spider)
|
66 |
|
67 |
-
# Ventas del cliente 2021-2024
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
fig_sales = px.line(x=years, y=customer_sales, markers=True, title=f'Sales Over the Years for Customer {customer_code}')
|
73 |
-
fig_sales.update_layout(xaxis_title="Year", yaxis_title="Sales")
|
74 |
-
st.plotly_chart(fig_sales)
|
75 |
|
|
|
|
|
|
|
|
|
|
|
76 |
else:
|
77 |
st.warning(f"No data found for customer {customer_code}. Please check the code.")
|
78 |
|
@@ -87,8 +91,8 @@ elif page == "Customer Recommendations":
|
|
87 |
customer_code = st.text_input("Enter Customer Code for Recommendations")
|
88 |
|
89 |
if customer_code:
|
90 |
-
customer_data = df[df[
|
91 |
-
|
92 |
if not customer_data.empty:
|
93 |
# Mostrar historial de compras del cliente seleccionado
|
94 |
st.write(f"### Purchase History for Customer {customer_code}")
|
|
|
7 |
st.set_page_config(page_title="Customer Insights App", page_icon=":bar_chart:")
|
8 |
|
9 |
# Cargar el archivo CSV que ya está disponible en la web
|
10 |
+
df = pd.read_csv("df_clean.csv") # Asegúrate de que la ruta del archivo es correcta
|
11 |
+
|
12 |
+
# Ignorar las dos últimas columnas
|
13 |
+
df = df.iloc[:, :-2]
|
14 |
|
15 |
# Diseño de la página principal
|
16 |
st.title("Welcome to Customer Insights App")
|
|
|
39 |
|
40 |
if customer_code:
|
41 |
# Filtrar datos para el cliente seleccionado
|
42 |
+
customer_data = df[df.iloc[:, 0] == customer_code] # Buscar cliente en la primera columna
|
43 |
|
44 |
if not customer_data.empty:
|
45 |
st.write(f"### Analysis for Customer {customer_code}")
|
46 |
+
|
47 |
+
# Obtener las 15 columnas con los valores más altos (ignorar la columna de cliente)
|
48 |
+
top_15_manufacturers = customer_data.iloc[:, 1:].T.nlargest(15, customer_data.index[0])
|
49 |
+
|
50 |
+
# Generar el spider chart con los top 15 fabricantes
|
51 |
fig_spider = go.Figure()
|
52 |
fig_spider.add_trace(go.Scatterpolar(
|
53 |
+
r=top_15_manufacturers[customer_data.index[0]].values,
|
54 |
+
theta=top_15_manufacturers.index,
|
55 |
fill='toself',
|
56 |
name=f'Customer {customer_code}'
|
57 |
))
|
|
|
59 |
polar=dict(
|
60 |
radialaxis=dict(
|
61 |
visible=True,
|
62 |
+
range=[0, top_15_manufacturers[customer_data.index[0]].max() + 1]
|
63 |
)),
|
64 |
showlegend=False,
|
65 |
+
title=f'Spider Chart for Top 15 Manufacturers of Customer {customer_code}'
|
66 |
)
|
67 |
st.plotly_chart(fig_spider)
|
68 |
|
69 |
+
# Ventas del cliente 2021-2024 (si los datos existen)
|
70 |
+
if 'VENTA_2021' in df.columns and 'VENTA_2022' in df.columns and 'VENTA_2023' in df.columns and 'VENTA_2024' in df.columns:
|
71 |
+
years = ['2021', '2022', '2023', '2024']
|
72 |
+
sales_columns = ['VENTA_2021', 'VENTA_2022', 'VENTA_2023', 'VENTA_2024']
|
73 |
+
customer_sales = customer_data[sales_columns].values[0]
|
|
|
|
|
|
|
74 |
|
75 |
+
fig_sales = px.line(x=years, y=customer_sales, markers=True, title=f'Sales Over the Years for Customer {customer_code}')
|
76 |
+
fig_sales.update_layout(xaxis_title="Year", yaxis_title="Sales")
|
77 |
+
st.plotly_chart(fig_sales)
|
78 |
+
else:
|
79 |
+
st.warning("Sales data for 2021-2024 not available.")
|
80 |
else:
|
81 |
st.warning(f"No data found for customer {customer_code}. Please check the code.")
|
82 |
|
|
|
91 |
customer_code = st.text_input("Enter Customer Code for Recommendations")
|
92 |
|
93 |
if customer_code:
|
94 |
+
customer_data = df[df.iloc[:, 0] == customer_code]
|
95 |
+
|
96 |
if not customer_data.empty:
|
97 |
# Mostrar historial de compras del cliente seleccionado
|
98 |
st.write(f"### Purchase History for Customer {customer_code}")
|
df_clean.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
info.csv
DELETED
File without changes
|