vgosavi2 commited on
Commit
a498ab9
·
verified ·
1 Parent(s): 3523535

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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['RegionName']
277
- .value_counts()
278
- .reset_index()
279
- .rename(columns={'index':'Region', 'RegionName':'Count'})
280
  )
281
- top_regions = region_counts.head(10)
282
 
283
  # 2. Build the bubble chart
284
  fig = px.scatter(
285
  top_regions,
286
- x='Region',
287
  y='Count',
288
  size='Count', # bubble area ∝ incident count
289
  color='Count', # color scale also shows volume
290
- hover_name='Region', # 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)'
 
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)'