Spaces:
Sleeping
Sleeping
File size: 1,866 Bytes
f6174cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
def render():
st.header("Análisis de Datos")
st.markdown("Sube tus archivos CSV o Excel para realizar un análisis exploratorio rápido.")
uploaded_file = st.file_uploader("Elige un archivo", type=["csv", "xlsx"])
if uploaded_file is not None:
try:
if uploaded_file.name.endswith('.csv'):
df = pd.read_csv(uploaded_file)
else:
df = pd.read_excel(uploaded_file)
st.subheader("Vista Previa de los Datos")
st.dataframe(df.head())
st.subheader("Estadísticas Descriptivas")
st.write(df.describe())
st.subheader("Información de Columnas")
st.write(df.dtypes)
st.subheader("Visualización")
numeric_cols = df.select_dtypes(include=['number']).columns.tolist()
if numeric_cols:
col_x = st.selectbox("Selecciona eje X", numeric_cols)
col_y = st.selectbox("Selecciona eje Y", numeric_cols)
chart_type = st.radio("Tipo de gráfico", ["Dispersión (Scatter)", "Líneas", "Histograma"])
fig, ax = plt.subplots()
if chart_type == "Dispersión (Scatter)":
sns.scatterplot(data=df, x=col_x, y=col_y, ax=ax)
elif chart_type == "Líneas":
sns.lineplot(data=df, x=col_x, y=col_y, ax=ax)
else:
sns.histplot(df[col_x], kde=True, ax=ax)
st.pyplot(fig)
plt.close(fig)
else:
st.warning("No se encontraron columnas numéricas para graficar.")
except Exception as e:
st.error(f"Error al procesar el archivo: {e}") |