wanwanlin0521 commited on
Commit
f48431c
·
verified ·
1 Parent(s): 02f01ce

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -9
src/streamlit_app.py CHANGED
@@ -131,7 +131,7 @@ col3.metric(
131
  value=f"{top_share:.1%}"
132
  )
133
 
134
- # Plotly donut chart ──
135
  fig = px.pie(
136
  top_crimes,
137
  names="Crime Type",
@@ -163,8 +163,6 @@ st.markdown(""" The donut chart shows the share of the ten most frequent crime c
163
 
164
 
165
  # -------------------------------- Plot 2: Heat Map --------------------------------
166
- top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
167
- df_top = df[df['crm_cd_desc'].isin(top_crimes)]
168
 
169
  # Count the crime type and list out the top 10 crime type that have the most cases.
170
  top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
@@ -203,6 +201,7 @@ This heatmap shows the frequency of the top 10 crimes from 2020 to 2025. The x a
203
 
204
 
205
  # -------------------------------- Plot 3: Line Chart --------------------------------
 
206
  df = df[df['year'] != 2025] # 2025 is not end, so the trend can't be see
207
 
208
  # Group the each crime type by year.
@@ -303,10 +302,12 @@ This visualization uses Folium to build an interactive map of crime distribution
303
  """)
304
 
305
  # -------------------------------- Plot 4: Stacked Bar Chart --------------------------------
306
- # Count the crime type and list out the top 10 crime type that have the most cases.
307
- top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
308
- df = df[df['year'] != 2025]
309
- df_top = df[df['crm_cd_desc'].isin(top_crimes)]
 
 
310
 
311
  # Group by crime type and year.
312
  stacked_year_df = df_top.groupby(['year', 'crm_cd_desc']).size().reset_index(name='count')
@@ -334,8 +335,8 @@ By observing the plot, we can find out that 2022 had the most crimes, the year h
334
  """)
335
 
336
  # -------------------------------- Plot 5: Bar Chart --------------------------------
337
- top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
338
- df_top = df[df['crm_cd_desc'].isin(top_crimes)]
339
 
340
  # Group by crime type and year.
341
  heatmap1_df = df_top.groupby(['crm_cd_desc', 'year']).size().reset_index(name='count')
 
131
  value=f"{top_share:.1%}"
132
  )
133
 
134
+ # -------------------------------- Plot 1: Pie(Donut) Chart --------------------------------
135
  fig = px.pie(
136
  top_crimes,
137
  names="Crime Type",
 
163
 
164
 
165
  # -------------------------------- Plot 2: Heat Map --------------------------------
 
 
166
 
167
  # Count the crime type and list out the top 10 crime type that have the most cases.
168
  top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
 
201
 
202
 
203
  # -------------------------------- Plot 3: Line Chart --------------------------------
204
+ # Filter out the year 2025.
205
  df = df[df['year'] != 2025] # 2025 is not end, so the trend can't be see
206
 
207
  # Group the each crime type by year.
 
302
  """)
303
 
304
  # -------------------------------- Plot 4: Stacked Bar Chart --------------------------------
305
+ # # Filter out the year 2025.
306
+ # df = df[df['year'] != 2025]
307
+
308
+ # # Count the crime type and list out the top 10 crime type that have the most cases.
309
+ # top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
310
+ # df_top = df[df['crm_cd_desc'].isin(top_crimes)]
311
 
312
  # Group by crime type and year.
313
  stacked_year_df = df_top.groupby(['year', 'crm_cd_desc']).size().reset_index(name='count')
 
335
  """)
336
 
337
  # -------------------------------- Plot 5: Bar Chart --------------------------------
338
+ # top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
339
+ # df_top = df[df['crm_cd_desc'].isin(top_crimes)]
340
 
341
  # Group by crime type and year.
342
  heatmap1_df = df_top.groupby(['crm_cd_desc', 'year']).size().reset_index(name='count')