Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
c1, c2, = st.columns([7,7]) | |
with c2: | |
st.image('figures/gdmk_logo.png', width=100, caption='2023') | |
with c1: | |
st.image('figures/giz_logo.png', width=200, caption='Peru') | |
st.title('Estudio de Encuesta Integridad') | |
option0 = st.selectbox('Formato de Analisis: ', ('Textos', 'Gráficos')) | |
option3 = st.selectbox('Documento: ', ('Todos', 'Encuesta', 'Indicadores')) | |
# Load dataframe | |
file = st.file_uploader('Seleccione un archivo Excel: ') | |
if file is not None: | |
if option0 == 'Textos': | |
# Load the Excel file into a Pandas dataframe | |
df00 = pd.read_excel(file, engine='openpyxl') | |
# Show the dataframe in Streamlit | |
# Sidebar option | |
maprange = {'0 a 10%': 10, '10 a 20%': 20, '20 a 30%': 30, '30 a 40%': 40, '40 a 50%': 50} | |
option2 = st.selectbox('Franja de Discrepancia [0, 50]', ('0 a 10%', '10 a 20%', '20 a 30%', '30 a 40%', '40 a 50%')) | |
mapn = maprange[option2] | |
st.write('La franja de discrepancia mostrada es entre ', mapn-10, ' y ', mapn, '%') | |
option1 = st.selectbox('Clasificar resultados por:', ('Pregunta', 'Categoria')) | |
df = df00[(df00['diff'] > mapn-10) & (df00['diff'] < mapn)] | |
df = df[df['documento']==option3] | |
#st.write(df) | |
# Group dataframe by chosen option | |
if option1 == 'Pregunta': | |
grouped_df = df.groupby('pregunta') | |
elif option1 == 'Categoria': | |
grouped_df = df.groupby('cat_sup') | |
# Generate text with bullets | |
text = '' | |
for name, group in grouped_df: | |
cad01 = '\n\n > **'+ option1+ ': '+ name + '**' | |
st.write(cad01) | |
st.write('Cantidad de afirmaciones: ', len(group)) | |
texto_tot = '' | |
for index, row in group.iterrows(): | |
val0 = str(row['diff']) | |
text = '* En el rubro sobre ' + row.pregunta + ' la categoría ' + row.cat_sup + ' responde ' + \ | |
row.respuesta + ' un **' + val0 + '%** más que la categoría ' + row.cat_inf + '\n' | |
texto_tot = texto_tot + '\n' + text | |
st.write(texto_tot) | |
# Download link for text file | |
st.download_button(label='Descargar Reporte', data=texto_tot, file_name='reporte.txt', mime='text/plain') | |
else: | |
option21 = st.selectbox('Tipo de Consulta: ', ('Categoría', 'Pregunta', 'Total')) | |
if option21 == 'Total': | |
st.image('figures/discrepancias_heatmap.png', width=1200) | |
else: | |
st.write('En construcción...') | |