vgosavi2 commited on
Commit
203d110
·
verified ·
1 Parent(s): 8f9f24e

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +18 -16
src/streamlit_app.py CHANGED
@@ -269,23 +269,25 @@ fig.update_layout(
269
  # 4. Render
270
  st.plotly_chart(fig, use_container_width=True)
271
 
272
- # Aggregate counts by region & crime
273
- sun = (
274
- df
275
- .groupby(["RegionName","crm_cd_desc"])
276
- .size()
277
- .reset_index(name="Count")
278
- )
279
-
280
- fig = px.sunburst(
281
- sun,
282
- path=["RegionName","crm_cd_desc"],
283
- values="Count",
284
- color="Count",
285
- color_continuous_scale="Agsunset",
286
- title="Crime Distribution: Region → Crime Type"
 
 
 
287
  )
288
- fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
289
  st.plotly_chart(fig, use_container_width=True)
290
 
291
 
 
269
  # 4. Render
270
  st.plotly_chart(fig, use_container_width=True)
271
 
272
+ # Prepare source/target/value lists
273
+ grouped = tm.copy()
274
+ regions = list(grouped["RegionName"].unique())
275
+ crimes = list(grouped["crm_cd_desc"].unique())
276
+
277
+ labels = regions + crimes
278
+ source = grouped["RegionName"].apply(lambda x: labels.index(x))
279
+ target = grouped["crm_cd_desc"].apply(lambda x: labels.index(x))
280
+ value = grouped["Count"]
281
+
282
+ fig = go.Figure(data=[go.Sankey(
283
+ node=dict(label=labels, pad=15, thickness=20),
284
+ link=dict(source=source, target=target, value=value)
285
+ )])
286
+ fig.update_layout(
287
+ title_text="Sankey: Region → Crime Type Flows",
288
+ font_size=10,
289
+ margin=dict(t=50, l=25, r=25, b=25)
290
  )
 
291
  st.plotly_chart(fig, use_container_width=True)
292
 
293