Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -88,7 +88,14 @@ if viz_type == "Complaints by Housing Block and Type":
|
|
| 88 |
selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options)
|
| 89 |
|
| 90 |
# Filter data based on selected year
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
# Filter data based on date range (only for Complaints Over Time visualization)
|
| 94 |
if viz_type == "Complaints Over Time":
|
|
@@ -97,11 +104,7 @@ if viz_type == "Complaints Over Time":
|
|
| 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}")
|
|
@@ -288,31 +291,31 @@ elif viz_type == "Complaints Over Time":
|
|
| 288 |
elif viz_type == "Complaints by Housing Block and Type":
|
| 289 |
st.subheader("Complaints by Housing Block and Type")
|
| 290 |
|
| 291 |
-
# Filter the data based on the selected block
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
if selected_block != 'All Blocks':
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
columns='Type of Complaint',
|
| 304 |
-
values='Disposition',
|
| 305 |
-
aggfunc='count',
|
| 306 |
-
fill_value=0
|
| 307 |
-
)
|
| 308 |
|
| 309 |
# Ensure the pivoted data is numeric for plotting
|
| 310 |
complaint_pivot = complaint_pivot.astype(float)
|
| 311 |
|
|
|
|
| 312 |
fig = complaint_pivot.plot(kind='bar', stacked=True, colormap='inferno', figsize=(10, 6)).get_figure()
|
| 313 |
st.pyplot(fig)
|
| 314 |
|
| 315 |
-
|
| 316 |
st.write("""
|
| 317 |
**What this visualization shows:**
|
| 318 |
This line chart shows the trend of complaints over time, displaying the number of complaints reported for each day. It helps identify patterns, peaks, and trends in the complaints data.
|
|
|
|
| 88 |
selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options)
|
| 89 |
|
| 90 |
# Filter data based on selected year
|
| 91 |
+
if selected_year != 'All Time':
|
| 92 |
+
filtered_data = data[data['Year Reported'] == selected_year]
|
| 93 |
+
else:
|
| 94 |
+
filtered_data = data
|
| 95 |
+
|
| 96 |
+
# Further filter by Housing Block (if applicable)
|
| 97 |
+
if viz_type == "Complaints by Housing Block and Type" and selected_block != 'All Blocks':
|
| 98 |
+
filtered_data = filtered_data[filtered_data['Housing Block'] == selected_block]
|
| 99 |
|
| 100 |
# Filter data based on date range (only for Complaints Over Time visualization)
|
| 101 |
if viz_type == "Complaints Over Time":
|
|
|
|
| 104 |
(filtered_data['Date Reported'] <= pd.to_datetime(end_date))
|
| 105 |
]
|
| 106 |
else:
|
| 107 |
+
filtered_data_time = filtered_data # Just use the filtered data without date range for other visualizations
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
# Header for selected year
|
| 110 |
st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selected_year}")
|
|
|
|
| 291 |
elif viz_type == "Complaints by Housing Block and Type":
|
| 292 |
st.subheader("Complaints by Housing Block and Type")
|
| 293 |
|
| 294 |
+
# Filter the data based on the selected year and housing block
|
| 295 |
+
filtered_data_time = filtered_data # Use filtered_data if date range is not needed
|
| 296 |
+
if selected_year != 'All Time':
|
| 297 |
+
filtered_data_time = filtered_data_time[filtered_data_time['Year Reported'] == selected_year]
|
| 298 |
+
|
| 299 |
+
# Further filter by Housing Block (if applicable)
|
| 300 |
if selected_block != 'All Blocks':
|
| 301 |
+
filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
|
| 302 |
+
|
| 303 |
+
# Pivot the data based on the filtered data
|
| 304 |
+
complaint_pivot = filtered_data_time.pivot_table(
|
| 305 |
+
index='Housing Block',
|
| 306 |
+
columns='Type of Complaint',
|
| 307 |
+
values='Disposition',
|
| 308 |
+
aggfunc='count',
|
| 309 |
+
fill_value=0
|
| 310 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
# Ensure the pivoted data is numeric for plotting
|
| 313 |
complaint_pivot = complaint_pivot.astype(float)
|
| 314 |
|
| 315 |
+
# Plot the data
|
| 316 |
fig = complaint_pivot.plot(kind='bar', stacked=True, colormap='inferno', figsize=(10, 6)).get_figure()
|
| 317 |
st.pyplot(fig)
|
| 318 |
|
|
|
|
| 319 |
st.write("""
|
| 320 |
**What this visualization shows:**
|
| 321 |
This line chart shows the trend of complaints over time, displaying the number of complaints reported for each day. It helps identify patterns, peaks, and trends in the complaints data.
|