spatel54 commited on
Commit
d266120
·
verified ·
1 Parent(s): 7640ba5

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +18 -0
src/streamlit_app.py CHANGED
@@ -134,3 +134,21 @@ fig.update_layout(
134
  st.plotly_chart(fig, use_container_width=True)
135
  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. """)
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  st.plotly_chart(fig, use_container_width=True)
135
  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. """)
136
 
137
+ top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
138
+ df_top = df[df['crm_cd_desc'].isin(top_crimes)]
139
+
140
+ # Count the crime type and list out the top 10 crime type that have the most cases.
141
+ top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
142
+ df_top = df[df['crm_cd_desc'].isin(top_crimes)]
143
+
144
+ # Group by crime type and year.
145
+ heatmap1_data = df_top.groupby(['crm_cd_desc', 'year']).size().unstack(fill_value=0)
146
+
147
+ # Create the heat map.
148
+ plt.figure(figsize=(10, 6))
149
+ sns.heatmap(heatmap1_data, annot=True, fmt="d", cmap="YlOrRd")
150
+ plt.title("Top 10 Crime Types by Year")
151
+ plt.xlabel("Year")
152
+ plt.ylabel("Crime Type")
153
+ plt.tight_layout()
154
+ plt.show()