ralate2 commited on
Commit
353a94d
·
verified ·
1 Parent(s): 77f004b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -8
app.py CHANGED
@@ -412,6 +412,87 @@ 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
  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
 
@@ -420,10 +501,19 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
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 (if applicable)
424
  if selected_block != 'All Blocks':
425
  filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
426
 
 
 
 
 
 
 
 
 
 
427
  # Pivoting the data based on the filtered data
428
  complaint_pivot = filtered_data_time.pivot_table(
429
  index='Housing Block',
@@ -436,7 +526,7 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
436
  # Ensuring the pivoted data is numeric for plotting
437
  complaint_pivot = complaint_pivot.astype(float)
438
 
439
- # Desired order for the housing blocks
440
  desired_order = [
441
  '1 block', '100 block', '200 block', '300 block', '400 block', '500 block',
442
  '600 block', '700 block', '800 block', '900 block', '1000 block', '1100 block',
@@ -444,10 +534,7 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
444
  '1700 block', '1800 block', '1900 block', '2000 block', '2100 block',
445
  '2200 block', '2300 block', '2400 block', '2500 block', '2600 block',
446
  '2700 block', '2800 block', '2900 block', '3000 block', '3100 block',
447
- '3200 block', '3300 block', '3400 block', '3500 block', '3600 block',
448
- '3700 block', '3800 block', '3900 block', '4000 block', '4100 block',
449
- '4200 block', '4300 block', '4400 block', '4500 block', '4600 block',
450
- '4700 block', '4800 block', '4900 block', '5000 block'
451
  ]
452
 
453
  # Reordering the index of the pivot table according to the desired order
@@ -478,13 +565,13 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
478
  )
479
  cumulative_height += count
480
 
481
- # Display the plot in Streamlit
482
  st.pyplot(fig)
483
 
484
  # Description of the visualization
485
  st.write("""
486
  **What this visualization shows:**
487
- This bar chart displays the distribution of complaints by Housing Block and Complaint Type. The data is stacked to show the percentage of complaints per block, categorized by type. This allows for a quick comparison of the most common complaint types across different housing blocks. While the percentages may be challenging to read when data for all blocks is displayed, they become more valuable and easier to interpret when a single block is selected. Selecting a specific block allows for clearer insights into the proportion of each complaint type within that block, providing more actionable information.
488
 
489
  **Why it's interesting:**
490
  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.
@@ -495,6 +582,8 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
495
 
496
 
497
 
 
 
498
  # Footer
499
  st.markdown("---")
500
  st.markdown("Dataset provided by the City of Urbana Open Data Portal.")
 
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 = 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 (if applicable)
424
+ # if selected_block != 'All Blocks':
425
+ # filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
426
+
427
+ # # Pivoting the data based on the filtered data
428
+ # complaint_pivot = filtered_data_time.pivot_table(
429
+ # index='Housing Block',
430
+ # columns='Type of Complaint',
431
+ # values='Disposition',
432
+ # aggfunc='count',
433
+ # fill_value=0
434
+ # )
435
+
436
+ # # Ensuring the pivoted data is numeric for plotting
437
+ # complaint_pivot = complaint_pivot.astype(float)
438
+
439
+ # # Desired order for the housing blocks
440
+ # desired_order = [
441
+ # '1 block', '100 block', '200 block', '300 block', '400 block', '500 block',
442
+ # '600 block', '700 block', '800 block', '900 block', '1000 block', '1100 block',
443
+ # '1200 block', '1300 block', '1400 block', '1500 block', '1600 block',
444
+ # '1700 block', '1800 block', '1900 block', '2000 block', '2100 block',
445
+ # '2200 block', '2300 block', '2400 block', '2500 block', '2600 block',
446
+ # '2700 block', '2800 block', '2900 block', '3000 block', '3100 block',
447
+ # '3200 block', '3300 block', '3400 block', '3500 block', '3600 block',
448
+ # '3700 block', '3800 block', '3900 block', '4000 block', '4100 block',
449
+ # '4200 block', '4300 block', '4400 block', '4500 block', '4600 block',
450
+ # '4700 block', '4800 block', '4900 block', '5000 block'
451
+ # ]
452
+
453
+ # # Reordering the index of the pivot table according to the desired order
454
+ # complaint_pivot = complaint_pivot.reindex(desired_order)
455
+
456
+ # # Calculating percentages for each complaint type per housing block
457
+ # percentages = complaint_pivot.div(complaint_pivot.sum(axis=1), axis=0) * 100
458
+
459
+ # # Plotting the data
460
+ # fig = complaint_pivot.plot(kind='bar', stacked=True, colormap='inferno', figsize=(10, 6)).get_figure()
461
+
462
+ # # Adding percentage labels to the plot
463
+ # ax = fig.gca()
464
+ # for idx, block in enumerate(complaint_pivot.index):
465
+ # cumulative_height = 0
466
+ # for i, complaint_type in enumerate(complaint_pivot.columns):
467
+ # count = complaint_pivot.iloc[idx, i]
468
+ # percent = percentages.iloc[idx, i]
469
+ # if count > 0:
470
+ # # Compute the position for the percentage label
471
+ # x_pos = idx - 0.4 + 0.8 / 2 # Adjusting the position of the label
472
+ # y_pos = cumulative_height + count / 2
473
+ # ax.text(
474
+ # x_pos, y_pos, f"{percent:.1f}%",
475
+ # ha='center', va='center',
476
+ # fontsize=10, color='black',
477
+ # bbox=dict(facecolor='white', alpha=0.7, edgecolor='none')
478
+ # )
479
+ # cumulative_height += count
480
+
481
+ # # Display the plot in Streamlit
482
+ # st.pyplot(fig)
483
+
484
+ # # Description of the visualization
485
+ # st.write("""
486
+ # **What this visualization shows:**
487
+ # This bar chart displays the distribution of complaints by Housing Block and Complaint Type. The data is stacked to show the percentage of complaints per block, categorized by type. This allows for a quick comparison of the most common complaint types across different housing blocks. While the percentages may be challenging to read when data for all blocks is displayed, they become more valuable and easier to interpret when a single block is selected. Selecting a specific block allows for clearer insights into the proportion of each complaint type within that block, providing more actionable information.
488
+
489
+ # **Why it's interesting:**
490
+ # 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.
491
+
492
+ # **Color Scheme:**
493
+ # 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.
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
 
 
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
  # 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',
 
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
 
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.
 
582
 
583
 
584
 
585
+
586
+
587
  # Footer
588
  st.markdown("---")
589
  st.markdown("Dataset provided by the City of Urbana Open Data Portal.")