wanwanlin0521 commited on
Commit
23c20a6
·
verified ·
1 Parent(s): b2b49c3

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +29 -29
src/streamlit_app.py CHANGED
@@ -189,35 +189,35 @@ elif page == "Pie Chart":
189
  st.markdown(""" The donut chart shows the share of the ten most frequent crime categories in the selected year. At the center, you can see that Vehicle ­– Stolen is the single largest slice, accounting for roughly 18.7% of all incidents, The remaining five categories each represent between 3%–5% of total incidents—these include miscellaneous crimes, criminal threats, assault with a deadly weapon, burglary, and minor vandalism. By displaying both slice size and percentage labels, the chart makes it easy to compare how dominant property‐related offenses are, versus violent or lesser‐common crimes, in that year’s LAPD data. """)
190
 
191
  # Data processing.
192
- # Count the crime type and list out the top 10 crime type that have the most cases.
193
- top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
194
- df_top = df[df['crm_cd_desc'].isin(top_crimes)]
195
-
196
- # Filter out the year 2025 since it is not the end, so that the trend can't be see.
197
- df = df[df['year'] != 2025]
198
-
199
- # Group the each crime type by year.
200
- yearly_crime_counts = (
201
- df.groupby(["year", "crm_cd_desc"])
202
- .size()
203
- .reset_index(name="Count")
204
- )
205
-
206
- # Filter the crime types that have the most top 5 cases.
207
- top5_crimes = df["crm_cd_desc"].value_counts().nlargest(5).index
208
- filtered_crimes = yearly_crime_counts[yearly_crime_counts["crm_cd_desc"].isin(top5_crimes)]
209
-
210
- # Identify top 10 crime types
211
- top_10_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index.tolist()
212
-
213
- # Filter the main DataFrame to include only top 10 crimes
214
- df_top = df[df['crm_cd_desc'].isin(top_10_crimes)]
215
-
216
- # Group by crime type and year.
217
- stacked_year_df = df_top.groupby(['year', 'crm_cd_desc']).size().reset_index(name='count')
218
-
219
- # Group by crime type and year.
220
- heatmap1_df = df_top.groupby(['crm_cd_desc', 'year']).size().reset_index(name='count')
221
 
222
  # -------------------------------- Plot 2: Heat Map --------------------------------
223
  elif page == "Heat Map":
 
189
  st.markdown(""" The donut chart shows the share of the ten most frequent crime categories in the selected year. At the center, you can see that Vehicle ­– Stolen is the single largest slice, accounting for roughly 18.7% of all incidents, The remaining five categories each represent between 3%–5% of total incidents—these include miscellaneous crimes, criminal threats, assault with a deadly weapon, burglary, and minor vandalism. By displaying both slice size and percentage labels, the chart makes it easy to compare how dominant property‐related offenses are, versus violent or lesser‐common crimes, in that year’s LAPD data. """)
190
 
191
  # Data processing.
192
+ # Count the crime type and list out the top 10 crime type that have the most cases.
193
+ top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
194
+ df_top = df[df['crm_cd_desc'].isin(top_crimes)]
195
+
196
+ # Filter out the year 2025 since it is not the end, so that the trend can't be see.
197
+ df = df[df['year'] != 2025]
198
+
199
+ # Group the each crime type by year.
200
+ yearly_crime_counts = (
201
+ df.groupby(["year", "crm_cd_desc"])
202
+ .size()
203
+ .reset_index(name="Count")
204
+ )
205
+
206
+ # Filter the crime types that have the most top 5 cases.
207
+ top5_crimes = df["crm_cd_desc"].value_counts().nlargest(5).index
208
+ filtered_crimes = yearly_crime_counts[yearly_crime_counts["crm_cd_desc"].isin(top5_crimes)]
209
+
210
+ # Identify top 10 crime types
211
+ top_10_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index.tolist()
212
+
213
+ # Filter the main DataFrame to include only top 10 crimes
214
+ df_top = df[df['crm_cd_desc'].isin(top_10_crimes)]
215
+
216
+ # Group by crime type and year.
217
+ stacked_year_df = df_top.groupby(['year', 'crm_cd_desc']).size().reset_index(name='count')
218
+
219
+ # Group by crime type and year.
220
+ heatmap1_df = df_top.groupby(['crm_cd_desc', 'year']).size().reset_index(name='count')
221
 
222
  # -------------------------------- Plot 2: Heat Map --------------------------------
223
  elif page == "Heat Map":