ralate2 commited on
Commit
5b69b6a
·
verified ·
1 Parent(s): edea274

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -14
app.py CHANGED
@@ -77,30 +77,36 @@ viz_type = st.sidebar.selectbox("Select Visualization", [
77
  "Top Complaint Types", "Complaints Over Time", "Complaints by Housing Block and Type"
78
  ])
79
 
80
- # Date Range Selector for Complaints Over Time
81
- start_date = st.sidebar.date_input("Start Date", pd.to_datetime("2020-01-01"))
82
- end_date = st.sidebar.date_input("End Date", pd.to_datetime("2024-12-31"))
 
83
 
84
- # Dropdown for Housing Block
85
- block_options = ['All Blocks'] + sorted(data['Housing Block'].unique().tolist())
86
- selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options)
 
87
 
88
  # Filter data based on selected year
89
  filtered_data = data if selected_year == 'All Time' else data[data['Year Reported'] == selected_year]
90
 
91
- # Filter data based on date range
92
- filtered_data_time = filtered_data[
93
- (filtered_data['Date Reported'] >= pd.to_datetime(start_date)) &
94
- (filtered_data['Date Reported'] <= pd.to_datetime(end_date))
95
- ]
96
-
97
- # Filter data based on selected housing block
98
- if selected_block != 'All Blocks':
 
 
 
99
  filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
100
 
101
  # Header for selected year
102
  st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selected_year}")
103
 
 
104
  # Display metrics
105
  col1, col2 = st.columns(2)
106
  with col1:
 
77
  "Top Complaint Types", "Complaints Over Time", "Complaints by Housing Block and Type"
78
  ])
79
 
80
+ # Date Range Selector for Complaints Over Time (only show when Complaints Over Time is selected)
81
+ if viz_type == "Complaints Over Time":
82
+ start_date = st.sidebar.date_input("Start Date", pd.to_datetime("2020-01-01"))
83
+ end_date = st.sidebar.date_input("End Date", pd.to_datetime("2024-12-31"))
84
 
85
+ # Dropdown for Housing Block (only show when Complaints by Housing Block and Type is selected)
86
+ if viz_type == "Complaints by Housing Block and Type":
87
+ block_options = ['All Blocks'] + sorted(data['Housing Block'].unique().tolist())
88
+ selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options)
89
 
90
  # Filter data based on selected year
91
  filtered_data = data if selected_year == 'All Time' else data[data['Year Reported'] == selected_year]
92
 
93
+ # Filter data based on date range (only for Complaints Over Time visualization)
94
+ if viz_type == "Complaints Over Time":
95
+ filtered_data_time = filtered_data[
96
+ (filtered_data['Date Reported'] >= pd.to_datetime(start_date)) &
97
+ (filtered_data['Date Reported'] <= pd.to_datetime(end_date))
98
+ ]
99
+ else:
100
+ filtered_data_time = filtered_data
101
+
102
+ # Filter data based on selected housing block (only for Complaints by Housing Block visualization)
103
+ if viz_type == "Complaints by Housing Block and Type" and selected_block != 'All Blocks':
104
  filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
105
 
106
  # Header for selected year
107
  st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selected_year}")
108
 
109
+
110
  # Display metrics
111
  col1, col2 = st.columns(2)
112
  with col1: