GMARTINEZMILLA commited on
Commit
ea19f03
1 Parent(s): 449983f

feat: generated files

Browse files
Files changed (2) hide show
  1. app.py +36 -12
  2. euros_proveedores.csv +0 -0
app.py CHANGED
@@ -10,8 +10,10 @@ st.set_page_config(page_title="Customer Insights App", page_icon=":bar_chart:")
10
  # Load CSV files
11
  df = pd.read_csv("df_clean.csv")
12
  nombres_proveedores = pd.read_csv("nombres_proveedores.csv", sep=';')
 
13
 
14
  nombres_proveedores['codigo'] = nombres_proveedores['codigo'].astype(str)
 
15
 
16
  # Ignore the last two columns
17
  df = df.iloc[:, :-2]
@@ -25,7 +27,7 @@ def get_supplier_name(code):
25
  return name[0] if len(name) > 0 else code
26
 
27
  # Function to create radar chart
28
- def radar_chart(categories, values, title):
29
  # Number of variables
30
  N = len(categories)
31
 
@@ -36,18 +38,29 @@ def radar_chart(categories, values, title):
36
  # Initialize the plot
37
  fig, ax = plt.subplots(figsize=(12, 12), subplot_kw=dict(projection='polar'))
38
 
39
- # Draw polygon and fill it
40
- values += values[:1]
41
- ax.plot(angles, values, 'o-', linewidth=2, color='#FF69B4')
42
- ax.fill(angles, values, alpha=0.25, color='#FF69B4')
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  # Set axes
45
  ax.set_xticks(angles[:-1])
46
  ax.set_xticklabels(categories, size=8, wrap=True)
47
- ax.set_ylim(0, max(values) * 1.1)
48
 
49
  # Draw reference circles
50
- circles = np.linspace(0, max(values), 5)
51
  for circle in circles:
52
  ax.plot(angles, [circle]*len(angles), '--', color='gray', alpha=0.3, linewidth=0.5)
53
 
@@ -55,8 +68,9 @@ def radar_chart(categories, values, title):
55
  ax.set_yticklabels([])
56
  ax.spines['polar'].set_visible(False)
57
 
58
- # Add title
59
  plt.title(title, size=16, y=1.1)
 
60
 
61
  return fig
62
 
@@ -100,8 +114,9 @@ elif page == "Customer Analysis":
100
  if customer_code:
101
  # Filter data for the selected customer
102
  customer_data = df[df["CLIENTE"] == customer_code]
 
103
 
104
- if not customer_data.empty:
105
  st.write(f"### Analysis for Customer {customer_code}")
106
 
107
  # Define purchase threshold
@@ -117,18 +132,27 @@ elif page == "Customer Analysis":
117
  values = all_manufacturers[customer_data.index[0]].values.tolist()
118
  manufacturers = [get_supplier_name(m) for m in all_manufacturers.index.tolist()]
119
 
 
 
 
 
 
 
 
 
120
  # If there are fewer than 3 manufacturers, add a third one with value 0
121
  if len(manufacturers) < 3:
122
  manufacturers.append("Other")
123
  values.append(0)
 
124
 
125
  # Display the results for each manufacturer
126
  st.write(f"### Results for {len(manufacturers)} manufacturers (sorted):")
127
- for manufacturer, value in zip(manufacturers, values):
128
- st.write(f"{manufacturer} = {value:.4f}")
129
 
130
  # Create and display the radar chart
131
- fig = radar_chart(manufacturers, values, f'Radar Chart for {len(manufacturers)} Manufacturers of Customer {customer_code}')
132
  st.pyplot(fig)
133
 
134
  # Customer sales 2021-2024 (if data exists)
 
10
  # Load CSV files
11
  df = pd.read_csv("df_clean.csv")
12
  nombres_proveedores = pd.read_csv("nombres_proveedores.csv", sep=';')
13
+ euros_proveedor = pd.read_csv("euros_proveedor.csv", sep=',')
14
 
15
  nombres_proveedores['codigo'] = nombres_proveedores['codigo'].astype(str)
16
+ euros_proveedor['CLIENTE'] = euros_proveedor['CLIENTE'].astype(str)
17
 
18
  # Ignore the last two columns
19
  df = df.iloc[:, :-2]
 
27
  return name[0] if len(name) > 0 else code
28
 
29
  # Function to create radar chart
30
+ def radar_chart(categories, values, amounts, title):
31
  # Number of variables
32
  N = len(categories)
33
 
 
38
  # Initialize the plot
39
  fig, ax = plt.subplots(figsize=(12, 12), subplot_kw=dict(projection='polar'))
40
 
41
+ # Normalize values and amounts
42
+ max_value = max(values)
43
+ normalized_values = [v / max_value for v in values]
44
+ total_amount = sum(amounts)
45
+ normalized_amounts = [a / total_amount for a in amounts]
46
+
47
+ # Draw polygon for units and fill it
48
+ normalized_values += normalized_values[:1]
49
+ ax.plot(angles, normalized_values, 'o-', linewidth=2, color='#FF69B4', label='% Units')
50
+ ax.fill(angles, normalized_values, alpha=0.25, color='#FF69B4')
51
+
52
+ # Draw polygon for amounts and fill it
53
+ normalized_amounts += normalized_amounts[:1]
54
+ ax.plot(angles, normalized_amounts, 'o-', linewidth=2, color='#4B0082', label='% Spend')
55
+ ax.fill(angles, normalized_amounts, alpha=0.25, color='#4B0082')
56
 
57
  # Set axes
58
  ax.set_xticks(angles[:-1])
59
  ax.set_xticklabels(categories, size=8, wrap=True)
60
+ ax.set_ylim(0, max(max(normalized_values), max(normalized_amounts)) * 1.1)
61
 
62
  # Draw reference circles
63
+ circles = np.linspace(0, 1, 5)
64
  for circle in circles:
65
  ax.plot(angles, [circle]*len(angles), '--', color='gray', alpha=0.3, linewidth=0.5)
66
 
 
68
  ax.set_yticklabels([])
69
  ax.spines['polar'].set_visible(False)
70
 
71
+ # Add title and legend
72
  plt.title(title, size=16, y=1.1)
73
+ plt.legend(loc='upper right', bbox_to_anchor=(1.3, 1.1))
74
 
75
  return fig
76
 
 
114
  if customer_code:
115
  # Filter data for the selected customer
116
  customer_data = df[df["CLIENTE"] == customer_code]
117
+ customer_euros = euros_proveedor[euros_proveedor["CLIENTE"] == customer_code]
118
 
119
+ if not customer_data.empty and not customer_euros.empty:
120
  st.write(f"### Analysis for Customer {customer_code}")
121
 
122
  # Define purchase threshold
 
132
  values = all_manufacturers[customer_data.index[0]].values.tolist()
133
  manufacturers = [get_supplier_name(m) for m in all_manufacturers.index.tolist()]
134
 
135
+ # Get amounts in euros
136
+ amounts = []
137
+ for m in all_manufacturers.index.tolist():
138
+ if m in customer_euros.columns:
139
+ amounts.append(customer_euros[m].values[0])
140
+ else:
141
+ amounts.append(0)
142
+
143
  # If there are fewer than 3 manufacturers, add a third one with value 0
144
  if len(manufacturers) < 3:
145
  manufacturers.append("Other")
146
  values.append(0)
147
+ amounts.append(0)
148
 
149
  # Display the results for each manufacturer
150
  st.write(f"### Results for {len(manufacturers)} manufacturers (sorted):")
151
+ for manufacturer, value, amount in zip(manufacturers, values, amounts):
152
+ st.write(f"{manufacturer} = {value:.4f} units, €{amount:.2f}")
153
 
154
  # Create and display the radar chart
155
+ fig = radar_chart(manufacturers, values, amounts, f'Radar Chart for {len(manufacturers)} Manufacturers of Customer {customer_code}')
156
  st.pyplot(fig)
157
 
158
  # Customer sales 2021-2024 (if data exists)
euros_proveedores.csv ADDED
The diff for this file is too large to render. See raw diff