una tabla con muchos datos, con algun boton o slider de rango de fechas
To upload files, please first save the app
import streamlit as st
import pandas as pd
import numpy as np
from datetime import datetime, timedelta
# Generar datos de ejemplo
def generate_sample_data(n_rows=1000):
np.random.seed(42)
dates = pd.date_range(
start='2022-01-01',
end='2023-12-31',
periods=n_rows
)
data = {
'Fecha': dates,
'Cliente': np.random.choice(['Cliente A', 'Cliente B', 'Cliente C', 'Cliente D', 'Cliente E'], n_rows),
'Producto': np.random.choice(['Laptop', 'Smartphone', 'Tablet', 'Monitor', 'Teclado'], n_rows),
'Cantidad': np.random.randint(1, 50, n_rows),
'Precio': np.random.uniform(100, 2000, n_rows).round(2),
}
df = pd.DataFrame(data)
df['Total'] = df['Cantidad'] * df['Precio']
return df
# Crear el dataframe
df = generate_sample_data()
st.title('đ Tabla de Ventas con Filtro de Fechas')
# Crear el slider de fechas
min_date = df['Fecha'].min().date()
max_date = df['Fecha'].max().date()
col1, col2 = st.columns(2)
with col1:
start_date = st.date_input('Fecha inicial', min_date)
with col2:
end_date = st.date_input('Fecha final', max_date)
# Filtrar los datos segĂșn el rango de fechas seleccionado
mask = (df['Fecha'].dt.date >= start_date) & (df['Fecha'].dt.date <= end_date)
filtered_df = df.loc[mask]
# Mostrar estadĂsticas
st.subheader('đ Resumen')
col1, col2, col3 = st.columns(3)
with col1:
st.metric('Total Ventas', f"${filtered_df['Total'].sum():,.2f}")
with col2:
st.metric('Promedio por Venta', f"${filtered_df['Total'].mean():,.2f}")
with col3:
st.metric('NĂșmero de Ventas', f"{len(filtered_df):,}")
# Mostrar la tabla filtrada
st.subheader('đïž Datos filtrados')
st.dataframe(
filtered_df.style.format({
'Precio': '${:.2f}',
'Total': '${:.2f}'
}),
height=400
)
# Mostrar grĂĄfico de ventas por dĂa
st.subheader('đ Ventas diarias')
daily_sales = filtered_df.groupby('Fecha')['Total'].sum().reset_index()
st.line_chart(daily_sales.set_index('Fecha'))
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?