Spaces:
Runtime error
Runtime error
import pandas as pd | |
import streamlit as st | |
import plotly.express as px | |
st.set_page_config(page_title='Survey Results') | |
st.header('Survey Results') | |
st.subheader('the results of amount data') | |
# load dataframe | |
excel_file = 'complete_loan.xlsx' | |
sheet_name = 'completedloan' | |
df = pd.read_excel(excel_file, | |
sheet_name=sheet_name, | |
usecols='A:L', | |
header=0) | |
df_participants = pd.read_excel(excel_file, | |
sheet_name=sheet_name, | |
usecols='S:T', | |
header=0) | |
st.dataframe(df) | |
pie_chart = px.pie(df_participants, | |
title='Total Results', | |
values= 'participant', | |
names= 'purpose') | |
st.plotly_chart(pie_chart) | |
# streamlit selection | |
tujuan = df['purpose'].unique().tolist() | |
years = df['year'].unique().tolist() | |
year_selection = st.slider('year:', | |
min_value= min(years), | |
max_value= max(years), | |
value=(min(years), max(years))) | |
purpose_selection = st.multiselect('purpose:', | |
tujuan, | |
default=tujuan) | |
# filter selection | |
mask = (df['year'].between(*year_selection)) & (df['purpose'].isin(purpose_selection)) | |
number_of_result = df[mask].shape[0] | |
st.markdown(f'*The results: {number_of_result}*') | |
# group data frame | |
df_grouped = df[mask].groupby(by=['purpose']).count()[['year']] | |
df_grouped = df_grouped.reset_index() | |
# bar chart | |
bar_chart = px.bar(df_grouped, | |
x= 'purpose', | |
y='year', | |
text= 'purpose', | |
color_discrete_sequence= ['black']*len(df_grouped), | |
template='plotly_white') | |
st.plotly_chart(bar_chart) |