Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -78,7 +78,7 @@ st.sidebar.header("Dashboard Controls")
|
|
| 78 |
# Defining the visualization type (viz_type) selection
|
| 79 |
viz_type = st.sidebar.selectbox("Select Visualization", [
|
| 80 |
"Complaint Types", "Geographic Distribution", "Complaints by Disposition", "Submission Methods",
|
| 81 |
-
"Monthly Trends by Complaint Type", "Complaints Over Time", "Complaints by Housing Block and Type"
|
| 82 |
])
|
| 83 |
|
| 84 |
# Removing the year selection when certain visualizations are selected
|
|
@@ -412,6 +412,79 @@ elif viz_type == "Complaints by Housing Block and Type":
|
|
| 412 |
The 'inferno' color palette is used to represent different complaint types, with darker shades indicating a higher frequency of complaints. The stacked bar chart makes it easy to compare the distribution of complaints by block and type.
|
| 413 |
""")
|
| 414 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
# Footer
|
| 416 |
st.markdown("---")
|
| 417 |
st.markdown("Dataset provided by the City of Urbana Open Data Portal.")
|
|
|
|
| 78 |
# Defining the visualization type (viz_type) selection
|
| 79 |
viz_type = st.sidebar.selectbox("Select Visualization", [
|
| 80 |
"Complaint Types", "Geographic Distribution", "Complaints by Disposition", "Submission Methods",
|
| 81 |
+
"Monthly Trends by Complaint Type", "Complaints Over Time", "Complaints by Housing Block and Type","Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)"
|
| 82 |
])
|
| 83 |
|
| 84 |
# Removing the year selection when certain visualizations are selected
|
|
|
|
| 412 |
The 'inferno' color palette is used to represent different complaint types, with darker shades indicating a higher frequency of complaints. The stacked bar chart makes it easy to compare the distribution of complaints by block and type.
|
| 413 |
""")
|
| 414 |
|
| 415 |
+
elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)":
|
| 416 |
+
st.subheader("Complaints by Housing Block and Type- Incorporating Suggestions Based on Professor's Feedback")
|
| 417 |
+
|
| 418 |
+
# Filtering the data based on the selected year and housing block
|
| 419 |
+
filtered_data_time = filtered_data # Use filtered_data if date range is not needed
|
| 420 |
+
if selected_year != 'All Time':
|
| 421 |
+
filtered_data_time = filtered_data_time[filtered_data_time['Year Reported'] == selected_year]
|
| 422 |
+
|
| 423 |
+
# Further filtering by Housing Block
|
| 424 |
+
if selected_block != 'All Blocks':
|
| 425 |
+
filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
|
| 426 |
+
|
| 427 |
+
# Grouping data and pivot
|
| 428 |
+
complaint_counts = filtered_data_time.groupby(['Housing Block', 'Type of Complaint']).size().reset_index(name='Count')
|
| 429 |
+
complaint_counts['Housing Block'] = pd.Categorical(
|
| 430 |
+
complaint_counts['Housing Block'],
|
| 431 |
+
categories=desired_order,
|
| 432 |
+
ordered=True
|
| 433 |
+
)
|
| 434 |
+
|
| 435 |
+
complaint_pivot = complaint_counts.pivot_table(
|
| 436 |
+
index='Housing Block',
|
| 437 |
+
columns='Type of Complaint',
|
| 438 |
+
values='Count',
|
| 439 |
+
aggfunc='sum',
|
| 440 |
+
fill_value=0
|
| 441 |
+
)
|
| 442 |
+
complaint_pivot = complaint_pivot.reindex(desired_order)
|
| 443 |
+
percentages = complaint_pivot.div(complaint_pivot.sum(axis=1), axis=0) * 100
|
| 444 |
+
|
| 445 |
+
# Creating the plot
|
| 446 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 447 |
+
bar_width = 0.8
|
| 448 |
+
complaint_pivot.plot(
|
| 449 |
+
kind='bar',
|
| 450 |
+
stacked=True,
|
| 451 |
+
cmap='inferno',
|
| 452 |
+
width=bar_width,
|
| 453 |
+
ax=ax
|
| 454 |
+
)
|
| 455 |
+
|
| 456 |
+
# Adding percentage labels to the bars
|
| 457 |
+
for idx, block in enumerate(complaint_pivot.index):
|
| 458 |
+
cumulative_height = 0
|
| 459 |
+
for i, complaint_type in enumerate(complaint_pivot.columns):
|
| 460 |
+
count = complaint_pivot.iloc[idx, i]
|
| 461 |
+
percent = percentages.iloc[idx, i]
|
| 462 |
+
if count > 0:
|
| 463 |
+
# Compute the position for the percentage label
|
| 464 |
+
x_pos = idx - 0.4 + bar_width / 2
|
| 465 |
+
y_pos = cumulative_height + count / 2
|
| 466 |
+
ax.text(
|
| 467 |
+
x_pos, y_pos, f"{percent:.1f}%",
|
| 468 |
+
ha='center', va='center',
|
| 469 |
+
fontsize=10, color='black',
|
| 470 |
+
bbox=dict(facecolor='white', alpha=0.7, edgecolor='none')
|
| 471 |
+
)
|
| 472 |
+
cumulative_height += count
|
| 473 |
+
|
| 474 |
+
st.pyplot(fig)
|
| 475 |
+
|
| 476 |
+
st.write("""
|
| 477 |
+
**What this visualization shows:**
|
| 478 |
+
This bar chart displays the distribution of complaints by Housing Block and Complaint Type. The data is stacked to show the total number of complaints per block, categorized by type, with percentage labels displayed for each section. This allows for a quick comparison of the most common complaint types across different housing blocks and the relative proportion of each type.
|
| 479 |
+
|
| 480 |
+
**Why it's interesting:**
|
| 481 |
+
By analyzing the distribution of complaints by both block and type, organizations can identify specific areas where certain complaint types are more prevalent. This insight helps target interventions and allocate resources more efficiently based on the most common issues in different housing blocks. The percentage labels provide a clear view of the proportional representation of each complaint type within each block.
|
| 482 |
+
|
| 483 |
+
**Color Scheme:**
|
| 484 |
+
The 'inferno' color palette is used to represent different complaint types, with darker shades indicating a higher frequency of complaints. The stacked bar chart makes it easy to compare the distribution of complaints by block and type, while the percentage labels offer a clearer understanding of the proportions.
|
| 485 |
+
""")
|
| 486 |
+
|
| 487 |
+
|
| 488 |
# Footer
|
| 489 |
st.markdown("---")
|
| 490 |
st.markdown("Dataset provided by the City of Urbana Open Data Portal.")
|