wanwanlin0521 commited on
Commit
7c3c069
·
verified ·
1 Parent(s): f48431c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +3 -14
src/streamlit_app.py CHANGED
@@ -163,7 +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
-
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
169
  df_top = df[df['crm_cd_desc'].isin(top_crimes)]
@@ -201,8 +200,8 @@ This heatmap shows the frequency of the top 10 crimes from 2020 to 2025. The x a
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.
208
  yearly_crime_counts = (
@@ -235,7 +234,7 @@ st.markdown(""" This plot is a line chart visualizing the annual number of incid
235
 
236
 
237
  # -------------------------------- Plot 4: Map --------------------------------
238
- # Load data
239
  with open(GEOJSON_PATH, "r", encoding="utf-8") as f:
240
  geojson_data = json.load(f)
241
 
@@ -302,13 +301,6 @@ This visualization uses Folium to build an interactive map of crime distribution
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')
314
 
@@ -335,9 +327,6 @@ By observing the plot, we can find out that 2022 had the most crimes, the year h
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')
343
 
 
163
 
164
 
165
  # -------------------------------- Plot 2: Heat Map --------------------------------
 
166
  # Count the crime type and list out the top 10 crime type that have the most cases.
167
  top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
168
  df_top = df[df['crm_cd_desc'].isin(top_crimes)]
 
200
 
201
 
202
  # -------------------------------- Plot 3: Line Chart --------------------------------
203
+ # Filter out the year 2025 since it is not the end, so that the trend can't be see.
204
+ df = df[df['year'] != 2025]
205
 
206
  # Group the each crime type by year.
207
  yearly_crime_counts = (
 
234
 
235
 
236
  # -------------------------------- Plot 4: Map --------------------------------
237
+ # Load the data.
238
  with open(GEOJSON_PATH, "r", encoding="utf-8") as f:
239
  geojson_data = json.load(f)
240
 
 
301
  """)
302
 
303
  # -------------------------------- Plot 4: Stacked Bar Chart --------------------------------
 
 
 
 
 
 
 
304
  # Group by crime type and year.
305
  stacked_year_df = df_top.groupby(['year', 'crm_cd_desc']).size().reset_index(name='count')
306
 
 
327
  """)
328
 
329
  # -------------------------------- Plot 5: Bar Chart --------------------------------
 
 
 
330
  # Group by crime type and year.
331
  heatmap1_df = df_top.groupby(['crm_cd_desc', 'year']).size().reset_index(name='count')
332