vgosavi2 commited on
Commit
572bd34
·
verified ·
1 Parent(s): e92efe1

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +12 -2
src/streamlit_app.py CHANGED
@@ -31,7 +31,7 @@ except FileNotFoundError:
31
 
32
  # Path for crime data.
33
  DATA_PATH = Path(__file__).parent / "crime_data.csv" # /app/src/crime_data.csv
34
-
35
 
36
  # ── 0. Page configuration ──
37
  st.set_page_config(
@@ -110,6 +110,8 @@ st.markdown(
110
  @st.cache_data
111
  def load_data():
112
  return pd.read_csv(DATA_PATH)
 
 
113
 
114
  if st.button("🔄 Refresh Data"):
115
  st.cache_data.clear() # Clear the cache
@@ -117,9 +119,17 @@ if st.button("🔄 Refresh Data"):
117
 
118
  # 2. Load and early‐exit if missing
119
  df = load_data()
 
 
 
 
120
  if df.empty:
121
  st.stop()
122
-
 
 
 
 
123
  # 3. Data preview
124
  st.markdown("<div class='sectionheader'> Data Preview </div>", unsafe_allow_html=True)
125
  st.markdown(
 
31
 
32
  # Path for crime data.
33
  DATA_PATH = Path(__file__).parent / "crime_data.csv" # /app/src/crime_data.csv
34
+ REGION_DATA_PATH = Path(__file__).parent / "area_lookup.csv"
35
 
36
  # ── 0. Page configuration ──
37
  st.set_page_config(
 
110
  @st.cache_data
111
  def load_data():
112
  return pd.read_csv(DATA_PATH)
113
+ def region_load_data():
114
+ return pd.read_csv(REGION_DATA_PATH)
115
 
116
  if st.button("🔄 Refresh Data"):
117
  st.cache_data.clear() # Clear the cache
 
119
 
120
  # 2. Load and early‐exit if missing
121
  df = load_data()
122
+ lookup = region_load_data()
123
+ map_region = dict(zip(lookup["OBJECTID"], lookup["APREC"]))
124
+ map_precinct = dict(zip(lookup["OBJECTID"], lookup["PREC"]))
125
+
126
  if df.empty:
127
  st.stop()
128
+
129
+ # Map into new columns
130
+ df["RegionName"] = df["area"].map(map_region)
131
+ df["PrecinctCode"] = df["area"].map(map_precinct)
132
+
133
  # 3. Data preview
134
  st.markdown("<div class='sectionheader'> Data Preview </div>", unsafe_allow_html=True)
135
  st.markdown(