ralate2 commited on
Commit
8bbe668
·
verified ·
1 Parent(s): 353a94d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -23
app.py CHANGED
@@ -501,19 +501,20 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
501
  if selected_year != 'All Time':
502
  filtered_data_time = filtered_data_time[filtered_data_time['Year Reported'] == selected_year]
503
 
504
- # Further filtering by Housing Block
505
- if selected_block != 'All Blocks':
506
- filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
507
-
508
- # Removing the specified blocks (3400 block, 3500 block, 3600 block, ..., 5000 block)
509
  excluded_blocks = [
510
  '3400 block', '3500 block', '3600 block', '3700 block', '3800 block', '3900 block',
511
  '4000 block', '4100 block', '4200 block', '4300 block', '4400 block', '4500 block',
512
  '4600 block', '4700 block', '4800 block', '4900 block', '5000 block'
513
  ]
514
 
 
515
  filtered_data_time = filtered_data_time[~filtered_data_time['Housing Block'].isin(excluded_blocks)]
516
 
 
 
 
 
517
  # Pivoting the data based on the filtered data
518
  complaint_pivot = filtered_data_time.pivot_table(
519
  index='Housing Block',
@@ -526,19 +527,9 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
526
  # Ensuring the pivoted data is numeric for plotting
527
  complaint_pivot = complaint_pivot.astype(float)
528
 
529
- # Desired order for the housing blocks (excluding the blocks to be removed)
530
- desired_order = [
531
- '1 block', '100 block', '200 block', '300 block', '400 block', '500 block',
532
- '600 block', '700 block', '800 block', '900 block', '1000 block', '1100 block',
533
- '1200 block', '1300 block', '1400 block', '1500 block', '1600 block',
534
- '1700 block', '1800 block', '1900 block', '2000 block', '2100 block',
535
- '2200 block', '2300 block', '2400 block', '2500 block', '2600 block',
536
- '2700 block', '2800 block', '2900 block', '3000 block', '3100 block',
537
- '3200 block', '3300 block'
538
- ]
539
-
540
- # Reordering the index of the pivot table according to the desired order
541
- complaint_pivot = complaint_pivot.reindex(desired_order)
542
 
543
  # Calculating percentages for each complaint type per housing block
544
  percentages = complaint_pivot.div(complaint_pivot.sum(axis=1), axis=0) * 100
@@ -565,13 +556,13 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
565
  )
566
  cumulative_height += count
567
 
568
- # Displaying the plot in Streamlit
569
  st.pyplot(fig)
570
 
571
  # Description of the visualization
572
  st.write("""
573
  **What this visualization shows:**
574
- This bar chart displays the distribution of complaints by Housing Block and Complaint Type. The data is stacked to show the total percentage of complaints per block, categorized by type. This allows for a quick comparison of the most common complaint types across different housing blocks.
575
 
576
  **Why it's interesting:**
577
  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.
@@ -581,9 +572,6 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
581
  """)
582
 
583
 
584
-
585
-
586
-
587
  # Footer
588
  st.markdown("---")
589
  st.markdown("Dataset provided by the City of Urbana Open Data Portal.")
 
501
  if selected_year != 'All Time':
502
  filtered_data_time = filtered_data_time[filtered_data_time['Year Reported'] == selected_year]
503
 
504
+ # Remove the specified blocks (3400 block, 3500 block, 3600 block, ..., 5000 block)
 
 
 
 
505
  excluded_blocks = [
506
  '3400 block', '3500 block', '3600 block', '3700 block', '3800 block', '3900 block',
507
  '4000 block', '4100 block', '4200 block', '4300 block', '4400 block', '4500 block',
508
  '4600 block', '4700 block', '4800 block', '4900 block', '5000 block'
509
  ]
510
 
511
+ # Excluding the blocks from the data
512
  filtered_data_time = filtered_data_time[~filtered_data_time['Housing Block'].isin(excluded_blocks)]
513
 
514
+ # Further filtering by Housing Block (if applicable)
515
+ if selected_block != 'All Blocks':
516
+ filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
517
+
518
  # Pivoting the data based on the filtered data
519
  complaint_pivot = filtered_data_time.pivot_table(
520
  index='Housing Block',
 
527
  # Ensuring the pivoted data is numeric for plotting
528
  complaint_pivot = complaint_pivot.astype(float)
529
 
530
+ # If a specific block is selected, only show that block on the x-axis
531
+ if selected_block != 'All Blocks':
532
+ complaint_pivot = complaint_pivot.loc[[selected_block]]
 
 
 
 
 
 
 
 
 
 
533
 
534
  # Calculating percentages for each complaint type per housing block
535
  percentages = complaint_pivot.div(complaint_pivot.sum(axis=1), axis=0) * 100
 
556
  )
557
  cumulative_height += count
558
 
559
+ # Display the plot in Streamlit
560
  st.pyplot(fig)
561
 
562
  # Description of the visualization
563
  st.write("""
564
  **What this visualization shows:**
565
+ 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. This allows for a quick comparison of the most common complaint types across different housing blocks.
566
 
567
  **Why it's interesting:**
568
  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.
 
572
  """)
573
 
574
 
 
 
 
575
  # Footer
576
  st.markdown("---")
577
  st.markdown("Dataset provided by the City of Urbana Open Data Portal.")