vgosavi2 commited on
Commit
784e8fe
·
verified ·
1 Parent(s): 3d0b2c0

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -4
src/streamlit_app.py CHANGED
@@ -58,20 +58,26 @@ st.dataframe(df.head())
58
 
59
  # Pie Chart 1: Top 10 Crime Types
60
  st.markdown("<div class='title'><h1> Top 10 Crime Type </h1></div>", unsafe_allow_html=True)
 
61
  years = sorted(df["year"].dropna().astype(int).unique())
 
 
62
 
63
  # Year filter (shorter, above chart)
64
  col_empty, col_filter = st.columns([3,1])
65
  with col_filter:
66
  selected_year = st.selectbox(
67
  "Select Year",
68
- years,
69
- index=len(years)-1,
70
  key="year_filter"
71
  )
72
 
73
- # Filter data for that year
74
- filtered = df[df["year"] == selected_year]
 
 
 
75
 
76
  # Compute top 10 crime types for that year ──
77
  top_crimes = (
 
58
 
59
  # Pie Chart 1: Top 10 Crime Types
60
  st.markdown("<div class='title'><h1> Top 10 Crime Type </h1></div>", unsafe_allow_html=True)
61
+
62
  years = sorted(df["year"].dropna().astype(int).unique())
63
+ # Prepend an “All” option
64
+ options = ["All"] + years
65
 
66
  # Year filter (shorter, above chart)
67
  col_empty, col_filter = st.columns([3,1])
68
  with col_filter:
69
  selected_year = st.selectbox(
70
  "Select Year",
71
+ options=options,
72
+ index=0, # default to “All”
73
  key="year_filter"
74
  )
75
 
76
+ # Filter according to selection
77
+ if selected_year == "All":
78
+ filtered = df.copy()
79
+ else:
80
+ filtered = df[df["Year"] == selected_year]
81
 
82
  # Compute top 10 crime types for that year ──
83
  top_crimes = (