GMARTINEZMILLA commited on
Commit
af4b90c
1 Parent(s): 7a47c88

feat: generated files

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -12,26 +12,26 @@ 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
- # Convertir todas las columnas excepto 'CLIENTE' a float en euros_proveedor
19
  for col in euros_proveedor.columns:
20
  if col != 'CLIENTE':
21
  euros_proveedor[col] = pd.to_numeric(euros_proveedor[col], errors='coerce')
22
 
23
- # Verificar si hay valores NaN después de la conversión
24
  if euros_proveedor.isna().any().any():
25
- st.warning("Algunos valores en euros_proveedor no pudieron ser convertidos a números. Por favor, revise los datos de entrada.")
26
 
27
- # Ignore the last two columns
28
  df = df.iloc[:, :-2]
29
 
30
- # Ensure customer code is a string
31
- df['CLIENTE'] = df['CLIENTE'].astype(str)
32
-
33
  # Function to get supplier name
34
  def get_supplier_name(code):
 
35
  name = nombres_proveedores[nombres_proveedores['codigo'] == code]['nombre'].values
36
  return name[0] if len(name) > 0 else code
37
 
@@ -105,8 +105,8 @@ elif page == "Customer Analysis":
105
  customer_code = st.selectbox("Select Customer Code", customer_list)
106
 
107
  if customer_code:
108
- customer_data = df[df["CLIENTE"] == customer_code]
109
- customer_euros = euros_proveedor[euros_proveedor["CLIENTE"] == customer_code]
110
 
111
  if not customer_data.empty and not customer_euros.empty:
112
  st.write(f"### Analysis for Customer {customer_code}")
@@ -120,10 +120,10 @@ elif page == "Customer Analysis":
120
  sales_data.index = sales_data.index.astype(str)
121
 
122
  # Sort manufacturers by percentage of units and get top 10
123
- top_units = all_manufacturers.sort_values(by=customer_data.index[0], ascending=False).head(10)
124
 
125
  # Sort manufacturers by total sales and get top 10
126
- top_sales = sales_data.sort_values(by=customer_euros.index[0], ascending=False).head(10)
127
 
128
  # Combine top manufacturers from both lists
129
  combined_top = pd.concat([top_units, top_sales]).index.unique()
@@ -134,9 +134,9 @@ elif page == "Customer Analysis":
134
 
135
  for m in combined_top:
136
  if m in all_manufacturers.index and m in sales_data.index:
137
- values.append(float(all_manufacturers.loc[m, customer_data.index[0]]))
138
  manufacturers.append(get_supplier_name(m))
139
- amounts.append(float(sales_data.loc[m, customer_euros.index[0]]))
140
 
141
  st.write(f"### Results for top {len(manufacturers)} manufacturers (balanced by units % and total sales):")
142
  for manufacturer, value, amount in zip(manufacturers, values, amounts):
@@ -149,9 +149,9 @@ elif page == "Customer Analysis":
149
  st.warning("No data available to create the radar chart.")
150
 
151
  # Customer sales 2021-2024 (if data exists)
152
- if 'VENTA_2021' in df.columns and 'VENTA_2022' in df.columns and 'VENTA_2023' in df.columns and 'VENTA_2024' in df.columns:
 
153
  years = ['2021', '2022', '2023', '2024']
154
- sales_columns = ['VENTA_2021', 'VENTA_2022', 'VENTA_2023', 'VENTA_2024']
155
  customer_sales = customer_data[sales_columns].values[0]
156
 
157
  fig_sales = px.line(x=years, y=customer_sales, markers=True, title=f'Sales Over the Years for Customer {customer_code}')
@@ -178,7 +178,7 @@ elif page == "Customer Recommendations":
178
  customer_code = st.selectbox("Select Customer Code for Recommendations", customer_list)
179
 
180
  if customer_code:
181
- customer_data = df[df["CLIENTE"] == customer_code]
182
 
183
  if not customer_data.empty:
184
  st.write(f"### Purchase History for Customer {customer_code}")
 
12
  nombres_proveedores = pd.read_csv("nombres_proveedores.csv", sep=';')
13
  euros_proveedor = pd.read_csv("euros_proveedor.csv", sep=',')
14
 
15
+ # Ensure customer codes are strings
16
+ df['CLIENTE'] = df['CLIENTE'].astype(str)
17
  nombres_proveedores['codigo'] = nombres_proveedores['codigo'].astype(str)
18
  euros_proveedor['CLIENTE'] = euros_proveedor['CLIENTE'].astype(str)
19
 
20
+ # Convert all columns except 'CLIENTE' to float in euros_proveedor
21
  for col in euros_proveedor.columns:
22
  if col != 'CLIENTE':
23
  euros_proveedor[col] = pd.to_numeric(euros_proveedor[col], errors='coerce')
24
 
25
+ # Check for NaN values after conversion
26
  if euros_proveedor.isna().any().any():
27
+ st.warning("Some values in euros_proveedor couldn't be converted to numbers. Please review the input data.")
28
 
29
+ # Ignore the last two columns of df
30
  df = df.iloc[:, :-2]
31
 
 
 
 
32
  # Function to get supplier name
33
  def get_supplier_name(code):
34
+ code = str(code) # Ensure code is a string
35
  name = nombres_proveedores[nombres_proveedores['codigo'] == code]['nombre'].values
36
  return name[0] if len(name) > 0 else code
37
 
 
105
  customer_code = st.selectbox("Select Customer Code", customer_list)
106
 
107
  if customer_code:
108
+ customer_data = df[df["CLIENTE"] == str(customer_code)]
109
+ customer_euros = euros_proveedor[euros_proveedor["CLIENTE"] == str(customer_code)]
110
 
111
  if not customer_data.empty and not customer_euros.empty:
112
  st.write(f"### Analysis for Customer {customer_code}")
 
120
  sales_data.index = sales_data.index.astype(str)
121
 
122
  # Sort manufacturers by percentage of units and get top 10
123
+ top_units = all_manufacturers.sort_values(by=all_manufacturers.columns[0], ascending=False).head(10)
124
 
125
  # Sort manufacturers by total sales and get top 10
126
+ top_sales = sales_data.sort_values(by=sales_data.columns[0], ascending=False).head(10)
127
 
128
  # Combine top manufacturers from both lists
129
  combined_top = pd.concat([top_units, top_sales]).index.unique()
 
134
 
135
  for m in combined_top:
136
  if m in all_manufacturers.index and m in sales_data.index:
137
+ values.append(float(all_manufacturers.loc[m, all_manufacturers.columns[0]]))
138
  manufacturers.append(get_supplier_name(m))
139
+ amounts.append(float(sales_data.loc[m, sales_data.columns[0]]))
140
 
141
  st.write(f"### Results for top {len(manufacturers)} manufacturers (balanced by units % and total sales):")
142
  for manufacturer, value, amount in zip(manufacturers, values, amounts):
 
149
  st.warning("No data available to create the radar chart.")
150
 
151
  # Customer sales 2021-2024 (if data exists)
152
+ sales_columns = ['VENTA_2021', 'VENTA_2022', 'VENTA_2023', 'VENTA_2024']
153
+ if all(col in df.columns for col in sales_columns):
154
  years = ['2021', '2022', '2023', '2024']
 
155
  customer_sales = customer_data[sales_columns].values[0]
156
 
157
  fig_sales = px.line(x=years, y=customer_sales, markers=True, title=f'Sales Over the Years for Customer {customer_code}')
 
178
  customer_code = st.selectbox("Select Customer Code for Recommendations", customer_list)
179
 
180
  if customer_code:
181
+ customer_data = df[df["CLIENTE"] == str(customer_code)]
182
 
183
  if not customer_data.empty:
184
  st.write(f"### Purchase History for Customer {customer_code}")