Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -494,9 +494,9 @@ elif viz_type == "Complaints by Housing Block and Type":
|
|
| 494 |
# """)
|
| 495 |
|
| 496 |
elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)":
|
| 497 |
-
st.subheader("Complaints by Housing Block and Type- Incorporating Suggestions Based on Professor's Feedback")
|
| 498 |
|
| 499 |
-
# Define
|
| 500 |
excluded_blocks = [
|
| 501 |
'3400 block', '3500 block', '3600 block', '3700 block', '3800 block', '3900 block',
|
| 502 |
'4000 block', '4100 block', '4200 block', '4300 block', '4400 block', '4500 block',
|
|
@@ -514,19 +514,26 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
|
|
| 514 |
'3200 block', '3300 block'
|
| 515 |
]
|
| 516 |
|
| 517 |
-
# Filtering the data based on
|
| 518 |
filtered_data_time = data # Use filtered_data if date range is not needed
|
| 519 |
if selected_year != 'All Time':
|
| 520 |
filtered_data_time = filtered_data_time[filtered_data_time['Year Reported'] == selected_year]
|
| 521 |
|
| 522 |
-
#
|
| 523 |
filtered_data_time = filtered_data_time[~filtered_data_time['Housing Block'].isin(excluded_blocks)]
|
| 524 |
|
| 525 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
if selected_block != 'All Blocks':
|
| 527 |
filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
|
| 528 |
|
| 529 |
-
# Pivoting the data
|
| 530 |
complaint_pivot = filtered_data_time.pivot_table(
|
| 531 |
index='Housing Block',
|
| 532 |
columns='Type of Complaint',
|
|
@@ -535,10 +542,10 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
|
|
| 535 |
fill_value=0
|
| 536 |
)
|
| 537 |
|
| 538 |
-
#
|
| 539 |
complaint_pivot = complaint_pivot.astype(float)
|
| 540 |
|
| 541 |
-
# Reordering the
|
| 542 |
complaint_pivot = complaint_pivot.reindex(desired_order)
|
| 543 |
|
| 544 |
# If a specific block is selected, only show that block on the x-axis
|
|
@@ -585,8 +592,6 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
|
|
| 585 |
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.
|
| 586 |
""")
|
| 587 |
|
| 588 |
-
|
| 589 |
-
|
| 590 |
# Footer
|
| 591 |
st.markdown("---")
|
| 592 |
st.markdown("Dataset provided by the City of Urbana Open Data Portal.")
|
|
|
|
| 494 |
# """)
|
| 495 |
|
| 496 |
elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)":
|
| 497 |
+
st.subheader("Complaints by Housing Block and Type - Incorporating Suggestions Based on Professor's Feedback")
|
| 498 |
|
| 499 |
+
# Define blocks to be excluded
|
| 500 |
excluded_blocks = [
|
| 501 |
'3400 block', '3500 block', '3600 block', '3700 block', '3800 block', '3900 block',
|
| 502 |
'4000 block', '4100 block', '4200 block', '4300 block', '4400 block', '4500 block',
|
|
|
|
| 514 |
'3200 block', '3300 block'
|
| 515 |
]
|
| 516 |
|
| 517 |
+
# Filtering the data based on selected year
|
| 518 |
filtered_data_time = data # Use filtered_data if date range is not needed
|
| 519 |
if selected_year != 'All Time':
|
| 520 |
filtered_data_time = filtered_data_time[filtered_data_time['Year Reported'] == selected_year]
|
| 521 |
|
| 522 |
+
# Exclude blocks from the data
|
| 523 |
filtered_data_time = filtered_data_time[~filtered_data_time['Housing Block'].isin(excluded_blocks)]
|
| 524 |
|
| 525 |
+
# Get the list of blocks excluding the unwanted ones
|
| 526 |
+
available_blocks = sorted(filtered_data_time['Housing Block'].unique().tolist())
|
| 527 |
+
|
| 528 |
+
# Dropdown for Housing Block (excluding unwanted blocks)
|
| 529 |
+
block_options = ['All Blocks'] + available_blocks
|
| 530 |
+
selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options, key="block_select")
|
| 531 |
+
|
| 532 |
+
# Further filtering by selected Housing Block (if applicable)
|
| 533 |
if selected_block != 'All Blocks':
|
| 534 |
filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
|
| 535 |
|
| 536 |
+
# Pivoting the data
|
| 537 |
complaint_pivot = filtered_data_time.pivot_table(
|
| 538 |
index='Housing Block',
|
| 539 |
columns='Type of Complaint',
|
|
|
|
| 542 |
fill_value=0
|
| 543 |
)
|
| 544 |
|
| 545 |
+
# Ensure the pivot data is numeric for plotting
|
| 546 |
complaint_pivot = complaint_pivot.astype(float)
|
| 547 |
|
| 548 |
+
# Reordering the pivot table by the desired order (excluding unwanted blocks)
|
| 549 |
complaint_pivot = complaint_pivot.reindex(desired_order)
|
| 550 |
|
| 551 |
# If a specific block is selected, only show that block on the x-axis
|
|
|
|
| 592 |
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.
|
| 593 |
""")
|
| 594 |
|
|
|
|
|
|
|
| 595 |
# Footer
|
| 596 |
st.markdown("---")
|
| 597 |
st.markdown("Dataset provided by the City of Urbana Open Data Portal.")
|