Spaces:
Runtime error
Runtime error
jcmachicao
commited on
Commit
•
803b4f5
1
Parent(s):
64ec483
Upload app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,67 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
|
4 |
-
c1, c2,
|
5 |
-
with
|
6 |
-
st.image('
|
7 |
with c1:
|
8 |
-
st.image('
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Load dataframe
|
11 |
file = st.file_uploader('Seleccione un archivo Excel: ')
|
12 |
|
13 |
if file is not None:
|
14 |
-
# Load the Excel file into a Pandas dataframe
|
15 |
-
df = pd.read_excel(file, engine='openpyxl')
|
16 |
-
# Show the dataframe in Streamlit
|
17 |
-
#st.write(df.head())
|
18 |
-
#st.write(list(df.columns))
|
19 |
-
|
20 |
-
# Sidebar option
|
21 |
-
option = st.sidebar.selectbox('Clasificar resultados por:', ('Pregunta', 'Categoria'))
|
22 |
-
|
23 |
-
# Group dataframe by chosen option
|
24 |
-
if option == 'Pregunta':
|
25 |
-
grouped_df = df.groupby('Pregunta')
|
26 |
-
elif option == 'Categoria':
|
27 |
-
grouped_df = df.groupby('Categoria')
|
28 |
-
|
29 |
-
# Generate text with bullets
|
30 |
-
text = ''
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
|
4 |
+
c1, c2, = st.columns([7,7])
|
5 |
+
with c2:
|
6 |
+
st.image('figures/gdmk_logo.png', width=100, caption='2023')
|
7 |
with c1:
|
8 |
+
st.image('figures/giz_logo.png', width=200, caption='Peru')
|
9 |
+
|
10 |
+
st.title('Estudio de Encuesta Integridad')
|
11 |
+
option0 = st.selectbox('Formato de Analisis: ', ('Textos', 'Gráficos'))
|
12 |
+
option3 = st.selectbox('Documento: ', ('Todos', 'Encuesta', 'Indicadores'))
|
13 |
|
14 |
# Load dataframe
|
15 |
file = st.file_uploader('Seleccione un archivo Excel: ')
|
16 |
|
17 |
if file is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
if option0 == 'Textos':
|
20 |
+
# Load the Excel file into a Pandas dataframe
|
21 |
+
df00 = pd.read_excel(file, engine='openpyxl')
|
22 |
+
# Show the dataframe in Streamlit
|
23 |
+
|
24 |
+
# Sidebar option
|
25 |
+
|
26 |
+
maprange = {'0 a 10%': 10, '10 a 20%': 20, '20 a 30%': 30, '30 a 40%': 40, '40 a 50%': 50}
|
27 |
+
option2 = st.selectbox('Franja de Discrepancia [0, 50]', ('0 a 10%', '10 a 20%', '20 a 30%', '30 a 40%', '40 a 50%'))
|
28 |
+
mapn = maprange[option2]
|
29 |
+
st.write('La franja de discrepancia mostrada es entre ', mapn-10, ' y ', mapn, '%')
|
30 |
+
option1 = st.selectbox('Clasificar resultados por:', ('Pregunta', 'Categoria'))
|
31 |
+
df = df00[(df00['diff'] > mapn-10) & (df00['diff'] < mapn)]
|
32 |
+
df = df[df['documento']==option3]
|
33 |
+
#st.write(df)
|
34 |
+
|
35 |
+
# Group dataframe by chosen option
|
36 |
+
if option1 == 'Pregunta':
|
37 |
+
grouped_df = df.groupby('pregunta')
|
38 |
+
elif option1 == 'Categoria':
|
39 |
+
grouped_df = df.groupby('cat_sup')
|
40 |
+
|
41 |
+
# Generate text with bullets
|
42 |
+
text = ''
|
43 |
+
|
44 |
+
for name, group in grouped_df:
|
45 |
+
|
46 |
+
cad01 = '\n\n > **'+ option1+ ': '+ name + '**'
|
47 |
+
st.write(cad01)
|
48 |
+
st.write('Cantidad de afirmaciones: ', len(group))
|
49 |
+
texto_tot = ''
|
50 |
+
for index, row in group.iterrows():
|
51 |
+
val0 = str(row['diff'])
|
52 |
+
text = '* En el rubro sobre ' + row.pregunta + ' la categoría ' + row.cat_sup + ' responde ' + \
|
53 |
+
row.respuesta + ' un **' + val0 + '%** más que la categoría ' + row.cat_inf + '\n'
|
54 |
+
texto_tot = texto_tot + '\n' + text
|
55 |
+
st.write(texto_tot)
|
56 |
+
|
57 |
+
# Download link for text file
|
58 |
+
st.download_button(label='Descargar Reporte', data=texto_tot, file_name='reporte.txt', mime='text/plain')
|
59 |
+
|
60 |
+
else:
|
61 |
+
option21 = st.selectbox('Tipo de Consulta: ', ('Categoría', 'Pregunta', 'Total'))
|
62 |
+
|
63 |
+
if option21 == 'Total':
|
64 |
+
st.image('figures/discrepancias_heatmap.png', width=1200)
|
65 |
+
else:
|
66 |
+
st.write('En construcción...')
|
67 |
+
|