Spaces:
Sleeping
Sleeping
Commit
路
9418a23
1
Parent(s):
ca83516
feat: updated website
Browse files
app.py
CHANGED
@@ -366,9 +366,12 @@ elif page == "Customer Analysis":
|
|
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
|
370 |
historical_data['fecha_mes'] = pd.to_datetime(historical_data['fecha_mes'], errors='coerce')
|
371 |
-
|
|
|
|
|
|
|
372 |
|
373 |
# Filtrar los datos hist贸ricos por cliente y por el rango de fechas (2023)
|
374 |
fecha_inicio_2023 = pd.to_datetime("2023-01-01")
|
@@ -380,18 +383,18 @@ elif page == "Customer Analysis":
|
|
380 |
(historical_data['fecha_mes'] <= fecha_fin_2023)
|
381 |
].groupby('fecha_mes')['precio_total'].sum().reset_index()
|
382 |
|
383 |
-
#
|
384 |
-
|
|
|
385 |
|
386 |
-
#
|
387 |
-
if datos_historicos.empty:
|
|
|
|
|
|
|
388 |
fechas_2023 = pd.date_range(start='2023-01-01', end='2023-12-31', freq='M')
|
389 |
datos_historicos = pd.DataFrame({'fecha_mes': fechas_2023, 'ventas_historicas': [0] * len(fechas_2023)})
|
390 |
|
391 |
-
# Renombrar la columna 'precio_total' a 'ventas_historicas' si hay datos
|
392 |
-
else:
|
393 |
-
datos_historicos.rename(columns={'precio_total': 'ventas_historicas'}, inplace=True)
|
394 |
-
|
395 |
# Filtrar los datos de predicciones y ventas reales para 2024
|
396 |
datos_cliente_total = results.groupby('fecha_mes').agg({
|
397 |
'ventas_reales': 'sum',
|
@@ -409,7 +412,12 @@ elif page == "Customer Analysis":
|
|
409 |
fechas_df_2024['fecha_mes'] = pd.to_datetime(fechas_df_2024['fecha_mes'], errors='coerce')
|
410 |
|
411 |
# Combinar datos hist贸ricos con predicciones y ventas reales usando un merge
|
412 |
-
|
|
|
|
|
|
|
|
|
|
|
413 |
|
414 |
# Rellenar los NaN: 0 en ventas_historicas donde faltan predicciones, y viceversa
|
415 |
datos_combinados['ventas_historicas'].fillna(0, inplace=True)
|
|
|
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 |
+
# Verificar los datos hist贸ricos del cliente
|
373 |
+
st.subheader("Verificar datos hist贸ricos del cliente")
|
374 |
+
st.write(historical_data[historical_data['cliente_id'] == customer_code_str].head()) # Mostrar algunos datos hist贸ricos para el cliente
|
375 |
|
376 |
# Filtrar los datos hist贸ricos por cliente y por el rango de fechas (2023)
|
377 |
fecha_inicio_2023 = pd.to_datetime("2023-01-01")
|
|
|
383 |
(historical_data['fecha_mes'] <= fecha_fin_2023)
|
384 |
].groupby('fecha_mes')['precio_total'].sum().reset_index()
|
385 |
|
386 |
+
# Verificar si los datos hist贸ricos fueron filtrados correctamente
|
387 |
+
st.subheader("Datos hist贸ricos filtrados (2023)")
|
388 |
+
st.write(datos_historicos)
|
389 |
|
390 |
+
# Renombrar la columna 'precio_total' a 'ventas_historicas' si no est谩 vac铆a
|
391 |
+
if not datos_historicos.empty:
|
392 |
+
datos_historicos.rename(columns={'precio_total': 'ventas_historicas'}, inplace=True)
|
393 |
+
else:
|
394 |
+
# Si los datos hist贸ricos est谩n vac铆os, generar fechas de 2023 con ventas_historicas = 0
|
395 |
fechas_2023 = pd.date_range(start='2023-01-01', end='2023-12-31', freq='M')
|
396 |
datos_historicos = pd.DataFrame({'fecha_mes': fechas_2023, 'ventas_historicas': [0] * len(fechas_2023)})
|
397 |
|
|
|
|
|
|
|
|
|
398 |
# Filtrar los datos de predicciones y ventas reales para 2024
|
399 |
datos_cliente_total = results.groupby('fecha_mes').agg({
|
400 |
'ventas_reales': 'sum',
|
|
|
412 |
fechas_df_2024['fecha_mes'] = pd.to_datetime(fechas_df_2024['fecha_mes'], errors='coerce')
|
413 |
|
414 |
# Combinar datos hist贸ricos con predicciones y ventas reales usando un merge
|
415 |
+
# Usamos how='outer' para asegurarnos de incluir todas las fechas de 2023 y 2024
|
416 |
+
datos_combinados = pd.merge(datos_historicos, datos_cliente_total, on='fecha_mes', how='outer').sort_values('fecha_mes')
|
417 |
+
|
418 |
+
# Verificar el DataFrame combinado antes de rellenar los valores faltantes
|
419 |
+
st.subheader("Datos combinados antes de llenar valores faltantes")
|
420 |
+
st.write(datos_combinados)
|
421 |
|
422 |
# Rellenar los NaN: 0 en ventas_historicas donde faltan predicciones, y viceversa
|
423 |
datos_combinados['ventas_historicas'].fillna(0, inplace=True)
|