GMARTINEZMILLA commited on
Commit
5b8b198
·
1 Parent(s): 7c03572

feat: updated app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -239,6 +239,7 @@ elif page == "Customer Analysis":
239
  st.write(f"Shape of euros_proveedor: {euros_proveedor.shape}")
240
 
241
  # Get percentage of units sold for each manufacturer
 
242
  all_manufacturers = customer_data.iloc[:, 1:].T # Exclude CLIENTE column
243
  all_manufacturers.index = all_manufacturers.index.astype(str)
244
 
@@ -305,16 +306,21 @@ elif page == "Customer Analysis":
305
  st.warning("No combined top manufacturers found.")
306
 
307
  # Customer sales 2021-2024 (if data exists)
308
- sales_columns = ['VENTA_2021', 'VENTA_2022', 'VENTA_2023', 'VENTA_2024']
309
- if all(col in df.columns for col in sales_columns):
310
- years = ['2021', '2022', '2023', '2024']
311
- customer_sales = customer_data[sales_columns].values[0]
312
-
313
- fig_sales = px.line(x=years, y=customer_sales, markers=True, title=f'Sales Over the Years for Customer {customer_code}')
314
- fig_sales.update_layout(xaxis_title="Year", yaxis_title="Sales")
315
- st.plotly_chart(fig_sales)
 
 
 
 
 
316
  else:
317
- st.warning("Sales data for 2021-2024 not available.")
318
  else:
319
  st.warning(f"No data found for customer {customer_code}. Please check the code.")
320
  else:
 
239
  st.write(f"Shape of euros_proveedor: {euros_proveedor.shape}")
240
 
241
  # Get percentage of units sold for each manufacturer
242
+ customer_df = df[df["CLIENTE"] == str(customer_code)]
243
  all_manufacturers = customer_data.iloc[:, 1:].T # Exclude CLIENTE column
244
  all_manufacturers.index = all_manufacturers.index.astype(str)
245
 
 
306
  st.warning("No combined top manufacturers found.")
307
 
308
  # Customer sales 2021-2024 (if data exists)
309
+ sales_columns = ['VENTA_2021', 'VENTA_2022', 'VENTA_2023']
310
+ if all(col in ventas_clientes.columns for col in sales_columns):
311
+ years = ['2021', '2022', '2023']
312
+ customer_sales_data = ventas_clientes[ventas_clientes['codigo_cliente'] == customer_code]
313
+
314
+ if not customer_sales_data.empty:
315
+ customer_sales = customer_sales_data[sales_columns].values[0]
316
+
317
+ fig_sales = px.line(x=years, y=customer_sales, markers=True, title=f'Sales Over the Years for Customer {customer_code}')
318
+ fig_sales.update_layout(xaxis_title="Year", yaxis_title="Sales")
319
+ st.plotly_chart(fig_sales)
320
+ else:
321
+ st.warning(f"No historical sales data found for customer {customer_code}")
322
  else:
323
+ st.warning("Sales data for 2021-2023 not available in the dataset.")
324
  else:
325
  st.warning(f"No data found for customer {customer_code}. Please check the code.")
326
  else: