chiaperez commited on
Commit
cd8353c
1 Parent(s): 00f690b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +188 -0
app.py ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import pandas as pd
3
+ import plotly.express as px
4
+ import streamlit as st
5
+
6
+
7
+ def load_data():
8
+ # Load the data
9
+ data = pd.read_csv(
10
+ "micro_world.csv"
11
+ )
12
+ return data
13
+
14
+
15
+ def introduction():
16
+ # Write the title and the subheader
17
+ st.title(
18
+ "Overview of Financial Accessibility in the Philippines"
19
+ )
20
+ st.subheader(
21
+ """
22
+ In line with the National Strategy for Financial Inclusion (NSFI) 2022-2028 by Bangko Sentral ng Pilipinas (BSP), this sprint aims to:
23
+ 1. Profile financial inclusion (FI) metrics in the Philippines using survey data from World Bank.
24
+ 2. Formulate policy recommendations to further improve access to financial services particularly to vulnerable sectors.
25
+ """
26
+ )
27
+
28
+ # Load photo
29
+ st.image("streamlit-photo-1.jpeg")
30
+
31
+ # Load data
32
+ data = load_data()
33
+
34
+ # Display data
35
+ st.markdown("**The Data**")
36
+ st.dataframe(data)
37
+ st.markdown("Source: Global Findex 2017 from World Bank.")
38
+
39
+
40
+ def fi_state_ph():
41
+ # Write the title
42
+ st.title(
43
+ "This is the current state of FI in the Philippines."
44
+ )
45
+
46
+ # Load data
47
+ data = load_data()
48
+
49
+ # Fetch Philippine data
50
+ philippine_data = data[
51
+ data['economy'] == 'Philippines'
52
+ ]
53
+
54
+ # Create another column for debit card ownership
55
+ philippine_data['has_debit_card'] = philippine_data['fin2'].apply(
56
+ lambda x: 1 if x == 1 else 0
57
+ )
58
+
59
+ # Compute overall debit card ownership
60
+ percent_debit_card_ownership = philippine_data['has_debit_card'].sum() * 100.0 / philippine_data[
61
+ 'wpid_random'].count()
62
+
63
+ # Partition the page into 2
64
+ col1, col2 = st.columns(2)
65
+
66
+ # Display text in column 1
67
+ col1.markdown(
68
+ "In the Philippines, there is still an opportunity to expand access to financial services: "
69
+ )
70
+
71
+ # Display metric in column 2
72
+ col2.metric(
73
+ label='% of Population with Debit Card',
74
+ value=percent_debit_card_ownership
75
+ )
76
+
77
+ # Display text
78
+ st.markdown("In terms of gender breakdown:")
79
+
80
+ # Create another column for gender
81
+ philippine_data['gender'] = philippine_data['female'].apply(
82
+ lambda x: 'male' if x == 1 else 'female'
83
+ )
84
+
85
+ # Compute breakdown of access to debit card by gender
86
+ debit_by_gender = philippine_data.groupby('gender').agg(
87
+ total_debit_card_owners=('has_debit_card', 'sum'),
88
+ total_population=('wpid_random', 'count')
89
+ ).reset_index()
90
+
91
+ # Compute % debit card ownership
92
+ debit_by_gender['% debit card ownership'] = debit_by_gender['total_debit_card_owners'] * 100.0 / debit_by_gender[
93
+ 'total_population']
94
+
95
+ # Plot the data
96
+ fig, ax = plt.subplots(figsize=(6, 3), dpi=200)
97
+ ax.bar(
98
+ debit_by_gender["gender"],
99
+ debit_by_gender["% debit card ownership"],
100
+ )
101
+ ax.set_xlabel("Gender")
102
+ ax.set_ylabel("% Debit Card Ownership")
103
+
104
+ # Show the data
105
+ st.pyplot(fig)
106
+
107
+
108
+ def fi_state_worldwide():
109
+ # Write the title and the subheader
110
+ st.title(
111
+ "This is the current state of FI worldwide."
112
+ )
113
+ st.markdown(
114
+ "**Here is a bubble map presenting the % of debit card ownership per country:**"
115
+ )
116
+
117
+ # Load data
118
+ data = load_data()
119
+
120
+ # Create another column for debit card ownership
121
+ data['has_debit_card'] = data['fin2'].apply(
122
+ lambda x: 1 if x == 1 else 0
123
+ )
124
+
125
+ # Group the data and apply aggregations
126
+ grouped_data = data.groupby(['economy', 'economycode', 'regionwb']).agg(
127
+ total_debit_card_owners=('has_debit_card', 'sum'),
128
+ total_population=('wpid_random', 'count')
129
+ ).reset_index()
130
+
131
+ # Compute debit card ownership in %
132
+ grouped_data['% of population with debit card'] = grouped_data['total_debit_card_owners'] * 100.0 / grouped_data[
133
+ 'total_population']
134
+
135
+ # Build the bubble map
136
+ fig = px.scatter_geo(
137
+ grouped_data,
138
+ locations="economycode",
139
+ color="regionwb",
140
+ hover_name="economy",
141
+ size="% of population with debit card",
142
+ projection="natural earth"
143
+ )
144
+
145
+ # Show the figure
146
+ st.plotly_chart(fig)
147
+
148
+
149
+ def recommendations():
150
+ # Write the title
151
+ st.title(
152
+ "What We Can Do"
153
+ )
154
+
155
+
156
+ def the_team():
157
+ # Write the title
158
+ st.title(
159
+ "The Team"
160
+ )
161
+
162
+
163
+ list_of_pages = [
164
+ "Towards Financial Inclusion",
165
+ "FI Status of the Philippines",
166
+ "FI Status Worldwide",
167
+ "What We Can Do",
168
+ "The Team"
169
+ ]
170
+
171
+ st.sidebar.title(':scroll: Main Pages')
172
+ selection = st.sidebar.radio("Go to: ", list_of_pages)
173
+
174
+ if selection == "Towards Financial Inclusion":
175
+ introduction()
176
+
177
+ elif selection == "FI Status of the Philippines":
178
+ fi_state_ph()
179
+
180
+ elif selection == "FI Status Worldwide":
181
+ fi_state_worldwide()
182
+
183
+ elif selection == "What We Can Do":
184
+ recommendations()
185
+
186
+ elif selection == "The Team":
187
+ the_team()
188
+