vgosavi2 commited on
Commit
92c4e53
Β·
verified Β·
1 Parent(s): 9dffac3

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +8 -16
src/streamlit_app.py CHANGED
@@ -91,29 +91,21 @@ st.altair_chart(chart1, use_container_width=True)
91
  ###############################################################
92
 
93
  import plotly.express as px
94
- # ── 3. Parse year from date ──
95
- # Detect the column containing β€œdate”
96
- date_col = next((c for c in df.columns if "date" in c.lower()), None)
97
- if date_col is None:
98
- st.error("Could not find a date column in the dataset.")
99
- st.stop()
100
-
101
- df[date_col] = pd.to_datetime(df[date_col], errors="coerce")
102
- df["Year"] = df[date_col].dt.year
103
 
104
- # ── 4. Year filter (above chart) ──
105
- years = sorted(df["Year"].dropna().unique())
106
  selected_year = st.selectbox("Select Year", years, index=len(years)-1)
107
 
108
- filtered = df[df["Year"] == selected_year]
 
109
 
110
  # ── 5. Compute top 10 crime types for that year ──
111
  top_crimes = (
112
  filtered["crm_cd_desc"]
113
- .value_counts()
114
- .nlargest(10)
115
- .rename_axis("Crime Type")
116
- .reset_index(name="Count")
117
  )
118
  top_crimes["Percentage"] = top_crimes["Count"] / top_crimes["Count"].sum()
119
 
 
91
  ###############################################################
92
 
93
  import plotly.express as px
 
 
 
 
 
 
 
 
 
94
 
95
+ # ── 3. Year filter (above chart) ──
96
+ years = sorted(df["year"].dropna().astype(int).unique())
97
  selected_year = st.selectbox("Select Year", years, index=len(years)-1)
98
 
99
+ # ── 4. Filter data for the selected year ──
100
+ filtered = df[df["year"] == selected_year]
101
 
102
  # ── 5. Compute top 10 crime types for that year ──
103
  top_crimes = (
104
  filtered["crm_cd_desc"]
105
+ .value_counts()
106
+ .nlargest(10)
107
+ .rename_axis("Crime Type")
108
+ .reset_index(name="Count")
109
  )
110
  top_crimes["Percentage"] = top_crimes["Count"] / top_crimes["Count"].sum()
111