Spaces:
Build error
Build error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +7 -7
src/streamlit_app.py
CHANGED
|
@@ -273,21 +273,21 @@ st.markdown("<div class='sectionheader'>Crime Hotspots by Region NO MAP</div>",
|
|
| 273 |
|
| 274 |
# 1. Aggregate total incidents by region and pick top 10
|
| 275 |
region_counts = (
|
| 276 |
-
df
|
| 277 |
-
.
|
| 278 |
-
.
|
| 279 |
-
.
|
| 280 |
)
|
| 281 |
-
top_regions = region_counts.head(10)
|
| 282 |
|
| 283 |
# 2. Build the bubble chart
|
| 284 |
fig = px.scatter(
|
| 285 |
top_regions,
|
| 286 |
-
x='
|
| 287 |
y='Count',
|
| 288 |
size='Count', # bubble area ∝ incident count
|
| 289 |
color='Count', # color scale also shows volume
|
| 290 |
-
hover_name='
|
| 291 |
hover_data={'Count':True},
|
| 292 |
size_max=60, # max bubble diameter
|
| 293 |
title='Top 10 Regions by Crime Volume (Bubble Chart)'
|
|
|
|
| 273 |
|
| 274 |
# 1. Aggregate total incidents by region and pick top 10
|
| 275 |
region_counts = (
|
| 276 |
+
df
|
| 277 |
+
.groupby("RegionName") # group by your text field
|
| 278 |
+
.size() # count rows
|
| 279 |
+
.reset_index(name="Count") # turn it into a DataFrame with columns RegionName & Count
|
| 280 |
)
|
| 281 |
+
top_regions = region_counts.head(10, "Count"))
|
| 282 |
|
| 283 |
# 2. Build the bubble chart
|
| 284 |
fig = px.scatter(
|
| 285 |
top_regions,
|
| 286 |
+
x='RegionName',
|
| 287 |
y='Count',
|
| 288 |
size='Count', # bubble area ∝ incident count
|
| 289 |
color='Count', # color scale also shows volume
|
| 290 |
+
hover_name='RegionName', # show region on hover
|
| 291 |
hover_data={'Count':True},
|
| 292 |
size_max=60, # max bubble diameter
|
| 293 |
title='Top 10 Regions by Crime Volume (Bubble Chart)'
|