Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,9 +72,8 @@ st.sidebar.header("Dashboard Controls")
|
|
| 72 |
|
| 73 |
# First, define the visualization type (viz_type) selection
|
| 74 |
viz_type = st.sidebar.selectbox("Select Visualization", [
|
| 75 |
-
"Complaint Types", "Geographic Distribution", "
|
| 76 |
-
"
|
| 77 |
-
"Top Complaint Types", "Complaints Over Time", "Complaints by Housing Block and Type"
|
| 78 |
])
|
| 79 |
|
| 80 |
# Remove the year selection when certain visualizations are selected
|
|
@@ -143,13 +142,13 @@ if viz_type == "Complaint Types":
|
|
| 143 |
top_complaints = filtered_data['Type of Complaint'].value_counts().nlargest(5).reset_index()
|
| 144 |
top_complaints.columns = ['Complaint Type', 'Count']
|
| 145 |
|
| 146 |
-
# Create an interactive pie chart with
|
| 147 |
fig = px.pie(
|
| 148 |
top_complaints,
|
| 149 |
names='Complaint Type',
|
| 150 |
values='Count',
|
| 151 |
title="Top 5 Complaint Types Distribution",
|
| 152 |
-
color_discrete_sequence=px.colors.
|
| 153 |
labels={"Count": "Number of Complaints", "Complaint Type": "Type of Complaint"},
|
| 154 |
hover_data=['Count']
|
| 155 |
)
|
|
@@ -161,14 +160,13 @@ if viz_type == "Complaint Types":
|
|
| 161 |
# Updated write-up
|
| 162 |
st.write("""
|
| 163 |
**What this visualization shows:**
|
| 164 |
-
This interactive pie chart displays the distribution of the top 5 complaint types.
|
| 165 |
**Why it's interesting:**
|
| 166 |
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.
|
| 167 |
**Color Scheme:**
|
| 168 |
-
Each complaint type is represented by a unique color
|
| 169 |
""")
|
| 170 |
|
| 171 |
-
|
| 172 |
elif viz_type == "Geographic Distribution":
|
| 173 |
st.subheader("Clustered Heatmap of Complaints")
|
| 174 |
|
|
@@ -192,64 +190,93 @@ elif viz_type == "Geographic Distribution":
|
|
| 192 |
""")
|
| 193 |
|
| 194 |
|
| 195 |
-
elif viz_type == "Resolution Status":
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
elif viz_type == "Submission Methods":
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
elif viz_type == "Complaints by Disposition":
|
| 237 |
st.subheader("Complaints by Disposition")
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
st.pyplot(fig)
|
| 242 |
|
| 243 |
st.write("""
|
| 244 |
**What this visualization shows:**
|
| 245 |
-
This bar chart displays the distribution of complaints by their
|
|
|
|
| 246 |
**Why it's interesting:**
|
| 247 |
-
By
|
|
|
|
| 248 |
**Color Scheme:**
|
| 249 |
-
The '
|
| 250 |
""")
|
| 251 |
|
| 252 |
|
|
|
|
| 253 |
elif viz_type == "Monthly Trends by Complaint Type":
|
| 254 |
st.subheader("Monthly Trends Grouped by Complaint Types")
|
| 255 |
monthly_trends = filtered_data.groupby(['Month Reported', 'Type of Complaint']).size().reset_index(name='Count')
|
|
@@ -272,23 +299,23 @@ elif viz_type == "Monthly Trends by Complaint Type":
|
|
| 272 |
""")
|
| 273 |
|
| 274 |
|
| 275 |
-
elif viz_type == "Top Complaint Types":
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
|
| 286 |
-
|
| 287 |
-
|
| 288 |
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
|
| 293 |
elif viz_type == "Complaints Over Time":
|
| 294 |
st.subheader("Complaints Over Time")
|
|
|
|
| 72 |
|
| 73 |
# First, define the visualization type (viz_type) selection
|
| 74 |
viz_type = st.sidebar.selectbox("Select Visualization", [
|
| 75 |
+
"Complaint Types", "Geographic Distribution", "Complaints by Disposition", "Monthly Trends by Complaint Type",
|
| 76 |
+
"Complaints Over Time", "Complaints by Housing Block and Type"
|
|
|
|
| 77 |
])
|
| 78 |
|
| 79 |
# Remove the year selection when certain visualizations are selected
|
|
|
|
| 142 |
top_complaints = filtered_data['Type of Complaint'].value_counts().nlargest(5).reset_index()
|
| 143 |
top_complaints.columns = ['Complaint Type', 'Count']
|
| 144 |
|
| 145 |
+
# Create an interactive pie chart with the 'inferno' color scheme
|
| 146 |
fig = px.pie(
|
| 147 |
top_complaints,
|
| 148 |
names='Complaint Type',
|
| 149 |
values='Count',
|
| 150 |
title="Top 5 Complaint Types Distribution",
|
| 151 |
+
color_discrete_sequence=px.colors.sequential.Inferno,
|
| 152 |
labels={"Count": "Number of Complaints", "Complaint Type": "Type of Complaint"},
|
| 153 |
hover_data=['Count']
|
| 154 |
)
|
|
|
|
| 160 |
# Updated write-up
|
| 161 |
st.write("""
|
| 162 |
**What this visualization shows:**
|
| 163 |
+
This interactive pie chart displays the distribution of the top 5 complaint types by year.
|
| 164 |
**Why it's interesting:**
|
| 165 |
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.
|
| 166 |
**Color Scheme:**
|
| 167 |
+
Each complaint type is represented by a unique color from the 'inferno' color scheme, which visually distinguishes between categories and makes the chart more engaging.
|
| 168 |
""")
|
| 169 |
|
|
|
|
| 170 |
elif viz_type == "Geographic Distribution":
|
| 171 |
st.subheader("Clustered Heatmap of Complaints")
|
| 172 |
|
|
|
|
| 190 |
""")
|
| 191 |
|
| 192 |
|
| 193 |
+
# elif viz_type == "Resolution Status":
|
| 194 |
+
# st.subheader("Interactive Complaint Resolution Status")
|
| 195 |
+
# resolution_counts = filtered_data['Disposition'].value_counts().reset_index()
|
| 196 |
+
# resolution_counts.columns = ['Disposition', 'Count']
|
| 197 |
+
# chart = alt.Chart(resolution_counts).mark_arc(innerRadius=50).encode(
|
| 198 |
+
# theta=alt.Theta(field="Count", type="quantitative"),
|
| 199 |
+
# color=alt.Color(field="Disposition", type="nominal"),
|
| 200 |
+
# tooltip=[
|
| 201 |
+
# alt.Tooltip("Disposition", title="Resolution"),
|
| 202 |
+
# alt.Tooltip("Count", title="Count")
|
| 203 |
+
# ]
|
| 204 |
+
# )
|
| 205 |
+
# st.altair_chart(chart, use_container_width=True)
|
| 206 |
+
|
| 207 |
+
# st.write("""
|
| 208 |
+
# **What this visualization shows:**
|
| 209 |
+
# This interactive donut chart displays the distribution of complaint resolutions, such as resolved, unresolved, or escalated cases.
|
| 210 |
+
# **Why it's interesting:**
|
| 211 |
+
# By analyzing the resolution status, we can assess the effectiveness of complaint handling and identify areas for improvement.
|
| 212 |
+
# **Color Scheme:**
|
| 213 |
+
# Each resolution status is represented by a distinct color, making it easy to differentiate between categories and quickly interpret the data.
|
| 214 |
+
# """)
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
# elif viz_type == "Submission Methods":
|
| 218 |
+
# st.subheader("Submission Methods Analysis")
|
| 219 |
+
# submission_counts = filtered_data['Method Submitted'].value_counts()
|
| 220 |
+
# fig, ax = plt.subplots(figsize=(10, 6))
|
| 221 |
+
# sns.barplot(x=submission_counts.values, y=submission_counts.index, palette='inferno', ax=ax)
|
| 222 |
+
# st.pyplot(fig)
|
| 223 |
+
|
| 224 |
+
# st.write("""
|
| 225 |
+
# **What this visualization shows:**
|
| 226 |
+
# This bar chart shows the number of complaints submitted via different methods, such as email, phone, online form, etc.
|
| 227 |
+
# **Why it's interesting:**
|
| 228 |
+
# By analyzing submission methods, we can understand how users prefer to submit complaints and focus on improving the most used channels.
|
| 229 |
+
# **Color Scheme:**
|
| 230 |
+
# The 'inferno' color palette is used to highlight differences in submission frequency, with darker shades indicating higher submission counts.
|
| 231 |
+
# """)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
# elif viz_type == "Complaints by Disposition":
|
| 235 |
+
# st.subheader("Complaints by Disposition")
|
| 236 |
+
# disposition_counts = filtered_data['Disposition'].value_counts()
|
| 237 |
+
# fig, ax = plt.subplots(figsize=(10, 6))
|
| 238 |
+
# sns.barplot(x=disposition_counts.values, y=disposition_counts.index, palette='viridis', ax=ax)
|
| 239 |
+
# st.pyplot(fig)
|
| 240 |
+
|
| 241 |
+
# st.write("""
|
| 242 |
+
# **What this visualization shows:**
|
| 243 |
+
# This bar chart displays the distribution of complaints by their resolution status (disposition), such as 'Resolved', 'Unresolved', etc.
|
| 244 |
+
# **Why it's interesting:**
|
| 245 |
+
# By examining the disposition of complaints, organizations can assess how effectively issues are being addressed and identify any areas needing improvement.
|
| 246 |
+
# **Color Scheme:**
|
| 247 |
+
# The 'viridis' color palette highlights differences in complaint resolution status, with lighter shades indicating a higher frequency of resolved complaints.
|
| 248 |
+
# """)
|
| 249 |
|
| 250 |
elif viz_type == "Complaints by Disposition":
|
| 251 |
st.subheader("Complaints by Disposition")
|
| 252 |
+
|
| 253 |
+
# Group by Complaint Type and Disposition to make the analysis more complex
|
| 254 |
+
disposition_by_complaint_type = filtered_data.groupby(['Type of Complaint', 'Disposition']).size().unstack(fill_value=0)
|
| 255 |
+
|
| 256 |
+
# Plot the bar chart with the 'inferno' color scheme
|
| 257 |
+
fig, ax = plt.subplots(figsize=(12, 8))
|
| 258 |
+
disposition_by_complaint_type.plot(kind='bar', stacked=True, colormap='inferno', ax=ax)
|
| 259 |
+
|
| 260 |
+
ax.set_title("Complaints by Disposition and Complaint Type")
|
| 261 |
+
ax.set_ylabel("Number of Complaints")
|
| 262 |
+
ax.set_xlabel("Complaint Type")
|
| 263 |
+
|
| 264 |
+
# Display the plot
|
| 265 |
st.pyplot(fig)
|
| 266 |
|
| 267 |
st.write("""
|
| 268 |
**What this visualization shows:**
|
| 269 |
+
This stacked bar chart displays the distribution of complaints by their disposition (e.g., 'Resolved', 'Unresolved') for each complaint type. The bars represent different complaint categories, and each bar is broken down by the resolution status.
|
| 270 |
+
|
| 271 |
**Why it's interesting:**
|
| 272 |
+
By combining complaint type and resolution status, this chart allows organizations to assess not only how many complaints are resolved or unresolved but also which types of complaints are most frequently resolved or still pending. This helps in identifying patterns in complaint resolution and provides insights into which complaint categories may need more attention to resolve.
|
| 273 |
+
|
| 274 |
**Color Scheme:**
|
| 275 |
+
The 'inferno' color scheme is used to differentiate between the various disposition statuses, with each status getting a unique shade. This gradient of colors helps visualize the proportions and makes the chart more visually engaging. Lighter shades correspond to a higher frequency of a particular disposition status in the given complaint type.
|
| 276 |
""")
|
| 277 |
|
| 278 |
|
| 279 |
+
|
| 280 |
elif viz_type == "Monthly Trends by Complaint Type":
|
| 281 |
st.subheader("Monthly Trends Grouped by Complaint Types")
|
| 282 |
monthly_trends = filtered_data.groupby(['Month Reported', 'Type of Complaint']).size().reset_index(name='Count')
|
|
|
|
| 299 |
""")
|
| 300 |
|
| 301 |
|
| 302 |
+
# elif viz_type == "Top Complaint Types":
|
| 303 |
+
# st.subheader("Top Complaint Types")
|
| 304 |
+
# complaint_counts = filtered_data['Type of Complaint'].value_counts().head(10)
|
| 305 |
+
# fig, ax = plt.subplots()
|
| 306 |
+
# sns.barplot(x=complaint_counts.values, y=complaint_counts.index, palette="inferno", ax=ax)
|
| 307 |
+
# st.pyplot(fig)
|
| 308 |
|
| 309 |
+
# st.write("""
|
| 310 |
+
# **What this visualization shows:**
|
| 311 |
+
# 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.
|
| 312 |
|
| 313 |
+
# **Why it's interesting:**
|
| 314 |
+
# 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.
|
| 315 |
|
| 316 |
+
# **Color Scheme:**
|
| 317 |
+
# The 'inferno' palette is used to emphasize the frequency of each complaint type, with darker shades representing higher frequencies.
|
| 318 |
+
# """)
|
| 319 |
|
| 320 |
elif viz_type == "Complaints Over Time":
|
| 321 |
st.subheader("Complaints Over Time")
|