Spaces:
Sleeping
Sleeping
Commit
路
ef48243
1
Parent(s):
a2d93bb
feat: updated website
Browse files
app.py
CHANGED
@@ -366,36 +366,15 @@ elif page == "Customer Analysis":
|
|
366 |
fecha_inicio = pd.to_datetime("2023-01-01")
|
367 |
fecha_corte = pd.to_datetime("2024-09-01")
|
368 |
|
369 |
-
st.subheader("Verificar existencia de datos en historical_data1")
|
370 |
-
st.write(historical_data.head())
|
371 |
-
|
372 |
# Convertir fecha_mes a datetime en el DataFrame historical_data
|
373 |
historical_data['fecha_mes'] = pd.to_datetime(historical_data['fecha_mes'], errors='coerce')
|
374 |
|
375 |
-
st.subheader("Verificar existencia de datos en historical_data1")
|
376 |
-
st.write(historical_data.head())
|
377 |
-
|
378 |
# Ensure cliente_id is of type string and strip any leading/trailing whitespace
|
379 |
historical_data['cliente_id'] = historical_data['cliente_id'].astype(str).str.strip()
|
380 |
customer_code_str = str(customer_code).strip() # Ensure the customer code is also properly formatted
|
381 |
|
382 |
-
# Display the unique cliente_id values to make sure they are correctly formatted
|
383 |
-
st.subheader("Verificar valores 煤nicos de cliente_id en historical_data")
|
384 |
-
st.write(historical_data['cliente_id'].unique()) # Show unique cliente_id values
|
385 |
-
|
386 |
-
# Show a sample of the data for the customer
|
387 |
-
st.subheader(f"Verificar datos para cliente_id {customer_code_str}")
|
388 |
filtered_historical_data = historical_data[historical_data['cliente_id'] == customer_code_str]
|
389 |
|
390 |
-
if not filtered_historical_data.empty:
|
391 |
-
st.success(f"Datos encontrados para cliente {customer_code_str}")
|
392 |
-
st.write(filtered_historical_data.head(20)) # Show more rows to confirm correct filtering
|
393 |
-
else:
|
394 |
-
st.error(f"No se encontraron datos para el cliente {customer_code_str}. Verifique el c贸digo.")
|
395 |
-
|
396 |
-
# Verificar los datos hist贸ricos del cliente
|
397 |
-
st.subheader("Verificar datos hist贸ricos del cliente")
|
398 |
-
st.write(historical_data[historical_data['cliente_id'] == customer_code_str].head()) # Mostrar algunos datos hist贸ricos para el cliente
|
399 |
|
400 |
# Filtrar los datos hist贸ricos por cliente y por el rango de fechas (2023)
|
401 |
fecha_inicio_2023 = pd.to_datetime("2023-01-01")
|
@@ -407,10 +386,6 @@ elif page == "Customer Analysis":
|
|
407 |
(historical_data['fecha_mes'] <= fecha_fin_2023)
|
408 |
].groupby('fecha_mes')['precio_total'].sum().reset_index()
|
409 |
|
410 |
-
# Verificar si los datos hist贸ricos fueron filtrados correctamente
|
411 |
-
st.subheader("Datos hist贸ricos filtrados (2023)")
|
412 |
-
st.write(datos_historicos)
|
413 |
-
|
414 |
# Renombrar la columna 'precio_total' a 'ventas_historicas' si no est谩 vac铆a
|
415 |
if not datos_historicos.empty:
|
416 |
datos_historicos.rename(columns={'precio_total': 'ventas_historicas'}, inplace=True)
|
@@ -439,22 +414,11 @@ elif page == "Customer Analysis":
|
|
439 |
# Usamos how='outer' para asegurarnos de incluir todas las fechas de 2023 y 2024
|
440 |
datos_combinados = pd.merge(datos_historicos, datos_cliente_total, on='fecha_mes', how='outer').sort_values('fecha_mes')
|
441 |
|
442 |
-
# Verificar el DataFrame combinado antes de rellenar los valores faltantes
|
443 |
-
st.subheader("Datos combinados antes de llenar valores faltantes")
|
444 |
-
st.write(datos_combinados)
|
445 |
-
|
446 |
# Rellenar los NaN: 0 en ventas_historicas donde faltan predicciones, y viceversa
|
447 |
datos_combinados['ventas_historicas'].fillna(0, inplace=True)
|
448 |
datos_combinados['ventas_predichas'].fillna(0, inplace=True)
|
449 |
datos_combinados['ventas_reales'].fillna(0, inplace=True)
|
450 |
|
451 |
-
# Mostrar los datos combinados
|
452 |
-
st.subheader("Datos combinados con valores faltantes llenados")
|
453 |
-
st.write(datos_combinados)
|
454 |
-
|
455 |
-
# **Generar la gr谩fica**
|
456 |
-
st.markdown("### Sales History, Predictions, and Real Sales")
|
457 |
-
|
458 |
# Crear la gr谩fica con Plotly
|
459 |
fig = go.Figure()
|
460 |
|
|
|
366 |
fecha_inicio = pd.to_datetime("2023-01-01")
|
367 |
fecha_corte = pd.to_datetime("2024-09-01")
|
368 |
|
|
|
|
|
|
|
369 |
# Convertir fecha_mes a datetime en el DataFrame historical_data
|
370 |
historical_data['fecha_mes'] = pd.to_datetime(historical_data['fecha_mes'], errors='coerce')
|
371 |
|
|
|
|
|
|
|
372 |
# Ensure cliente_id is of type string and strip any leading/trailing whitespace
|
373 |
historical_data['cliente_id'] = historical_data['cliente_id'].astype(str).str.strip()
|
374 |
customer_code_str = str(customer_code).strip() # Ensure the customer code is also properly formatted
|
375 |
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
filtered_historical_data = historical_data[historical_data['cliente_id'] == customer_code_str]
|
377 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
378 |
|
379 |
# Filtrar los datos hist贸ricos por cliente y por el rango de fechas (2023)
|
380 |
fecha_inicio_2023 = pd.to_datetime("2023-01-01")
|
|
|
386 |
(historical_data['fecha_mes'] <= fecha_fin_2023)
|
387 |
].groupby('fecha_mes')['precio_total'].sum().reset_index()
|
388 |
|
|
|
|
|
|
|
|
|
389 |
# Renombrar la columna 'precio_total' a 'ventas_historicas' si no est谩 vac铆a
|
390 |
if not datos_historicos.empty:
|
391 |
datos_historicos.rename(columns={'precio_total': 'ventas_historicas'}, inplace=True)
|
|
|
414 |
# Usamos how='outer' para asegurarnos de incluir todas las fechas de 2023 y 2024
|
415 |
datos_combinados = pd.merge(datos_historicos, datos_cliente_total, on='fecha_mes', how='outer').sort_values('fecha_mes')
|
416 |
|
|
|
|
|
|
|
|
|
417 |
# Rellenar los NaN: 0 en ventas_historicas donde faltan predicciones, y viceversa
|
418 |
datos_combinados['ventas_historicas'].fillna(0, inplace=True)
|
419 |
datos_combinados['ventas_predichas'].fillna(0, inplace=True)
|
420 |
datos_combinados['ventas_reales'].fillna(0, inplace=True)
|
421 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
# Crear la gr谩fica con Plotly
|
423 |
fig = go.Figure()
|
424 |
|