ralate2 commited on
Commit
fac1189
·
verified ·
1 Parent(s): 97667b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -11
app.py CHANGED
@@ -92,18 +92,18 @@ with col2:
92
 
93
  # Visualizations
94
  if viz_type == "Complaint Types":
95
- st.subheader("Interactive Complaint Types Pie Chart")
96
 
97
- # Prepare data
98
- complaint_counts = filtered_data['Type of Complaint'].value_counts().reset_index()
99
- complaint_counts.columns = ['Complaint Type', 'Count']
100
 
101
  # Create an interactive pie chart with hover tooltips
102
  fig = px.pie(
103
- complaint_counts,
104
  names='Complaint Type',
105
  values='Count',
106
- title="Distribution of Complaint Types",
107
  color_discrete_sequence=px.colors.qualitative.Set2,
108
  labels={"Count": "Number of Complaints", "Complaint Type": "Type of Complaint"},
109
  hover_data=['Count']
@@ -115,19 +115,37 @@ if viz_type == "Complaint Types":
115
 
116
  # Updated write-up
117
  st.write("""
118
- **Write-up:** This visualization displays the distribution of complaint types using an interactive pie chart.
119
- Hovering over each segment reveals the complaint type, the number of complaints, and its percentage of the total.
120
- The vibrant colors highlight differences between complaint categories, providing an accessible and informative view of the data.
 
 
 
121
  """)
122
 
123
 
124
  elif viz_type == "Geographic Distribution":
125
  st.subheader("Clustered Heatmap of Complaints")
 
 
126
  map_center = [filtered_data['Latitude'].mean(), filtered_data['Longitude'].mean()]
127
  m = folium.Map(location=map_center, zoom_start=12)
128
  heat_data = filtered_data[['Latitude', 'Longitude']].dropna().values.tolist()
129
  HeatMap(heat_data).add_to(m)
 
 
130
  st_folium(m, width=700, height=500)
 
 
 
 
 
 
 
 
 
 
 
131
 
132
  elif viz_type == "Resolution Status":
133
  st.subheader("Interactive Complaint Resolution Status")
@@ -135,10 +153,24 @@ elif viz_type == "Resolution Status":
135
  resolution_counts.columns = ['Disposition', 'Count']
136
  chart = alt.Chart(resolution_counts).mark_arc(innerRadius=50).encode(
137
  theta=alt.Theta(field="Count", type="quantitative"),
138
- color=alt.Color(field="Disposition", type="nominal")
 
 
 
 
139
  )
140
  st.altair_chart(chart, use_container_width=True)
141
 
 
 
 
 
 
 
 
 
 
 
142
  elif viz_type == "Submission Methods":
143
  st.subheader("Submission Methods Analysis")
144
  submission_counts = filtered_data['Method Submitted'].value_counts()
@@ -146,6 +178,16 @@ elif viz_type == "Submission Methods":
146
  sns.barplot(x=submission_counts.values, y=submission_counts.index, palette='inferno', ax=ax)
147
  st.pyplot(fig)
148
 
 
 
 
 
 
 
 
 
 
 
149
  elif viz_type == "Complaints by Disposition":
150
  st.subheader("Complaints by Disposition")
151
  disposition_counts = filtered_data['Disposition'].value_counts()
@@ -153,6 +195,16 @@ elif viz_type == "Complaints by Disposition":
153
  sns.barplot(x=disposition_counts.values, y=disposition_counts.index, palette='viridis', ax=ax)
154
  st.pyplot(fig)
155
 
 
 
 
 
 
 
 
 
 
 
156
  elif viz_type == "Monthly Trends by Complaint Type":
157
  st.subheader("Monthly Trends Grouped by Complaint Types")
158
  monthly_trends = filtered_data.groupby(['Month Reported', 'Type of Complaint']).size().reset_index(name='Count')
@@ -163,6 +215,18 @@ elif viz_type == "Monthly Trends by Complaint Type":
163
  )
164
  st.altair_chart(chart, use_container_width=True)
165
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  elif viz_type == "Top Complaint Types":
167
  st.subheader("Top Complaint Types")
168
  complaint_counts = filtered_data['Type of Complaint'].value_counts().head(10)
@@ -170,14 +234,34 @@ elif viz_type == "Top Complaint Types":
170
  sns.barplot(x=complaint_counts.values, y=complaint_counts.index, palette="inferno", ax=ax)
171
  st.pyplot(fig)
172
 
 
 
 
 
 
 
 
 
 
 
 
173
  elif viz_type == "Complaints Over Time":
174
  st.subheader("Complaints Over Time")
175
  complaints_over_time = filtered_data.groupby(filtered_data['Date Reported'].dt.date).size()
176
  fig, ax = plt.subplots()
177
- ax.plot(complaints_over_time.index, complaints_over_time.values, marker='o')
 
 
 
178
  ax.set_title("Complaints Over Time")
179
  st.pyplot(fig)
180
 
 
 
 
 
 
 
181
  elif viz_type == "Complaints by Housing Block and Type":
182
  st.subheader("Complaints by Housing Block and Type")
183
  complaint_pivot = filtered_data.pivot_table(
@@ -189,6 +273,16 @@ elif viz_type == "Complaints by Housing Block and Type":
189
  )
190
  fig = complaint_pivot.plot(kind='bar', stacked=True, colormap='inferno', figsize=(10, 6)).get_figure()
191
  st.pyplot(fig)
 
 
 
 
 
 
 
 
 
 
192
 
193
  # Footer
194
  st.markdown("---")
 
92
 
93
  # Visualizations
94
  if viz_type == "Complaint Types":
95
+ st.subheader("Top 5 Complaint Types Pie Chart")
96
 
97
+ # Prepare data: Select the top 5 complaint types
98
+ top_complaints = filtered_data['Type of Complaint'].value_counts().nlargest(5).reset_index()
99
+ top_complaints.columns = ['Complaint Type', 'Count']
100
 
101
  # Create an interactive pie chart with hover tooltips
102
  fig = px.pie(
103
+ top_complaints,
104
  names='Complaint Type',
105
  values='Count',
106
+ title="Top 5 Complaint Types Distribution",
107
  color_discrete_sequence=px.colors.qualitative.Set2,
108
  labels={"Count": "Number of Complaints", "Complaint Type": "Type of Complaint"},
109
  hover_data=['Count']
 
115
 
116
  # Updated write-up
117
  st.write("""
118
+ **What this visualization shows:**
119
+ This interactive pie chart displays the distribution of the top 5 complaint types.
120
+ **Why it's interesting:**
121
+ Hovering over each segment reveals detailed information, including the complaint type, the number of complaints, and its percentage of the total. By focusing on the top 5 complaint categories, this visualization helps identify the most commonly reported issues, enabling better prioritization of resources and targeted interventions.
122
+ **Color Scheme:**
123
+ Each complaint type is represented by a unique color, making it easy to differentiate between categories and interpret the data at a glance.
124
  """)
125
 
126
 
127
  elif viz_type == "Geographic Distribution":
128
  st.subheader("Clustered Heatmap of Complaints")
129
+
130
+ # Generate the heatmap
131
  map_center = [filtered_data['Latitude'].mean(), filtered_data['Longitude'].mean()]
132
  m = folium.Map(location=map_center, zoom_start=12)
133
  heat_data = filtered_data[['Latitude', 'Longitude']].dropna().values.tolist()
134
  HeatMap(heat_data).add_to(m)
135
+
136
+ # Display the map
137
  st_folium(m, width=700, height=500)
138
+
139
+ # Write-up
140
+ st.write("""
141
+ **What this visualization shows:**
142
+ This clustered heatmap visualizes complaint locations across the city.
143
+ **Why it's interesting:**
144
+ It highlights geographic areas with higher complaint densities, known as hotspots. These areas can be targeted for intervention and resource allocation.
145
+ **Color Scheme:**
146
+ The heatmap uses gradient colors, where warmer tones (red/orange) represent higher densities of complaints, providing a clear visual cue for problem areas.
147
+ """)
148
+
149
 
150
  elif viz_type == "Resolution Status":
151
  st.subheader("Interactive Complaint Resolution Status")
 
153
  resolution_counts.columns = ['Disposition', 'Count']
154
  chart = alt.Chart(resolution_counts).mark_arc(innerRadius=50).encode(
155
  theta=alt.Theta(field="Count", type="quantitative"),
156
+ color=alt.Color(field="Disposition", type="nominal"),
157
+ tooltip=[
158
+ alt.Tooltip("Disposition", title="Resolution"),
159
+ alt.Tooltip("Count", title="Count")
160
+ ]
161
  )
162
  st.altair_chart(chart, use_container_width=True)
163
 
164
+ st.write("""
165
+ **What this visualization shows:**
166
+ This interactive donut chart displays the distribution of complaint resolutions, such as resolved, unresolved, or escalated cases.
167
+ **Why it's interesting:**
168
+ By analyzing the resolution status, we can assess the effectiveness of complaint handling and identify areas for improvement.
169
+ **Color Scheme:**
170
+ Each resolution status is represented by a distinct color, making it easy to differentiate between categories and quickly interpret the data.
171
+ """)
172
+
173
+
174
  elif viz_type == "Submission Methods":
175
  st.subheader("Submission Methods Analysis")
176
  submission_counts = filtered_data['Method Submitted'].value_counts()
 
178
  sns.barplot(x=submission_counts.values, y=submission_counts.index, palette='inferno', ax=ax)
179
  st.pyplot(fig)
180
 
181
+ st.write("""
182
+ **What this visualization shows:**
183
+ This bar chart shows the number of complaints submitted via different methods, such as email, phone, online form, etc.
184
+ **Why it's interesting:**
185
+ By analyzing submission methods, we can understand how users prefer to submit complaints and focus on improving the most used channels.
186
+ **Color Scheme:**
187
+ The 'inferno' color palette is used to highlight differences in submission frequency, with darker shades indicating higher submission counts.
188
+ """)
189
+
190
+
191
  elif viz_type == "Complaints by Disposition":
192
  st.subheader("Complaints by Disposition")
193
  disposition_counts = filtered_data['Disposition'].value_counts()
 
195
  sns.barplot(x=disposition_counts.values, y=disposition_counts.index, palette='viridis', ax=ax)
196
  st.pyplot(fig)
197
 
198
+ st.write("""
199
+ **What this visualization shows:**
200
+ This bar chart displays the distribution of complaints by their resolution status (disposition), such as 'Resolved', 'Unresolved', etc.
201
+ **Why it's interesting:**
202
+ By examining the disposition of complaints, organizations can assess how effectively issues are being addressed and identify any areas needing improvement.
203
+ **Color Scheme:**
204
+ The 'viridis' color palette highlights differences in complaint resolution status, with lighter shades indicating a higher frequency of resolved complaints.
205
+ """)
206
+
207
+
208
  elif viz_type == "Monthly Trends by Complaint Type":
209
  st.subheader("Monthly Trends Grouped by Complaint Types")
210
  monthly_trends = filtered_data.groupby(['Month Reported', 'Type of Complaint']).size().reset_index(name='Count')
 
215
  )
216
  st.altair_chart(chart, use_container_width=True)
217
 
218
+ st.write("""
219
+ **What this visualization shows:**
220
+ This line chart visualizes the monthly trends in complaint counts, grouped by complaint type. It allows tracking changes in complaint frequencies over time and identifying patterns or spikes in specific categories.
221
+
222
+ **Why it's interesting:**
223
+ By visualizing these trends, you can identify whether certain complaint types are seasonal or are influenced by specific events. This information helps prioritize resources and refine strategies for complaint management.
224
+
225
+ **Color Scheme:**
226
+ Different complaint types are represented by distinct colors, enabling easy comparison of trends across categories.
227
+ """)
228
+
229
+
230
  elif viz_type == "Top Complaint Types":
231
  st.subheader("Top Complaint Types")
232
  complaint_counts = filtered_data['Type of Complaint'].value_counts().head(10)
 
234
  sns.barplot(x=complaint_counts.values, y=complaint_counts.index, palette="inferno", ax=ax)
235
  st.pyplot(fig)
236
 
237
+ st.write("""
238
+ **What this visualization shows:**
239
+ This bar chart displays the top 10 most common complaint types based on the number of occurrences. It provides a clear view of the most frequently reported issues.
240
+
241
+ **Why it's interesting:**
242
+ By focusing on the top complaint types, organizations can identify and prioritize the issues that impact the majority of their users or customers. This can lead to targeted improvements in service or support efforts.
243
+
244
+ **Color Scheme:**
245
+ The 'inferno' palette is used to emphasize the frequency of each complaint type, with darker shades representing higher frequencies.
246
+ """)
247
+
248
  elif viz_type == "Complaints Over Time":
249
  st.subheader("Complaints Over Time")
250
  complaints_over_time = filtered_data.groupby(filtered_data['Date Reported'].dt.date).size()
251
  fig, ax = plt.subplots()
252
+
253
+ # Apply color scheme to the plot
254
+ ax.plot(complaints_over_time.index, complaints_over_time.values, marker='o', color='tab:blue')
255
+
256
  ax.set_title("Complaints Over Time")
257
  st.pyplot(fig)
258
 
259
+ st.write("""
260
+ **Write-up:** This visualization displays the trend of complaints over time using a line chart.
261
+ It shows the number of complaints reported for each day, making it easy to spot peaks or declines in complaints.
262
+ The use of a blue color scheme highlights the flow and continuity of the data, providing a clear view of the patterns over time.
263
+ """)
264
+
265
  elif viz_type == "Complaints by Housing Block and Type":
266
  st.subheader("Complaints by Housing Block and Type")
267
  complaint_pivot = filtered_data.pivot_table(
 
273
  )
274
  fig = complaint_pivot.plot(kind='bar', stacked=True, colormap='inferno', figsize=(10, 6)).get_figure()
275
  st.pyplot(fig)
276
+ st.write("""
277
+ **What this visualization shows:**
278
+ This line chart shows the trend of complaints over time, displaying the number of complaints reported for each day. It helps identify patterns, peaks, and trends in the complaints data.
279
+
280
+ **Why it's interesting:**
281
+ By visualizing complaints over time, organizations can track the effectiveness of their responses and interventions. It also helps identify recurring spikes or declines in complaints, which could be indicative of specific events or issues.
282
+
283
+ **Insight Potential:**
284
+ This chart can be used to correlate with external factors, such as changes in policies, incidents, or other events that might lead to a sudden increase or decrease in complaints. The insights can inform better decision-making and improve the organization's complaint management strategy.
285
+ """)
286
 
287
  # Footer
288
  st.markdown("---")