Spaces:
Runtime error
Runtime error
Commit
•
30abd55
1
Parent(s):
6582c0d
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,63 @@
|
|
1 |
import pandas as pd
|
2 |
import streamlit as st
|
3 |
-
import
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import pandas as pd
|
2 |
import streamlit as st
|
3 |
+
import plotly.express as px
|
4 |
|
5 |
+
|
6 |
+
st.set_page_config(page_title='Survey Results')
|
7 |
+
st.header('Survey Results')
|
8 |
+
st.subheader('the results of amount data')
|
9 |
+
|
10 |
+
# load dataframe
|
11 |
+
excel_file = 'complete_loan.xlsx'
|
12 |
+
sheet_name = 'completedloan'
|
13 |
+
|
14 |
+
df = pd.read_excel(excel_file,
|
15 |
+
sheet_name=sheet_name,
|
16 |
+
usecols='A:L',
|
17 |
+
header=0)
|
18 |
+
|
19 |
+
df_participants = pd.read_excel(excel_file,
|
20 |
+
sheet_name=sheet_name,
|
21 |
+
usecols='S:T',
|
22 |
+
header=0)
|
23 |
+
|
24 |
+
st.dataframe(df)
|
25 |
+
|
26 |
+
pie_chart = px.pie(df_participants,
|
27 |
+
title='Total Results',
|
28 |
+
values= 'participant',
|
29 |
+
names= 'purpose')
|
30 |
+
|
31 |
+
st.plotly_chart(pie_chart)
|
32 |
+
|
33 |
+
# streamlit selection
|
34 |
+
tujuan = df['purpose'].unique().tolist()
|
35 |
+
years = df['year'].unique().tolist()
|
36 |
+
|
37 |
+
year_selection = st.slider('year:',
|
38 |
+
min_value= min(years),
|
39 |
+
max_value= max(years),
|
40 |
+
value=(min(years), max(years)))
|
41 |
+
|
42 |
+
purpose_selection = st.multiselect('purpose:',
|
43 |
+
tujuan,
|
44 |
+
default=tujuan)
|
45 |
+
|
46 |
+
# filter selection
|
47 |
+
mask = (df['year'].between(*year_selection)) & (df['purpose'].isin(purpose_selection))
|
48 |
+
number_of_result = df[mask].shape[0]
|
49 |
+
st.markdown(f'*The results: {number_of_result}*')
|
50 |
+
|
51 |
+
# group data frame
|
52 |
+
df_grouped = df[mask].groupby(by=['purpose']).count()[['year']]
|
53 |
+
|
54 |
+
df_grouped = df_grouped.reset_index()
|
55 |
+
|
56 |
+
# bar chart
|
57 |
+
bar_chart = px.bar(df_grouped,
|
58 |
+
x= 'purpose',
|
59 |
+
y='year',
|
60 |
+
text= 'purpose',
|
61 |
+
color_discrete_sequence= ['black']*len(df_grouped),
|
62 |
+
template='plotly_white')
|
63 |
+
st.plotly_chart(bar_chart)
|