Spaces:
Sleeping
Sleeping
Roberta2024
commited on
Commit
•
c7734b6
1
Parent(s):
723bba7
Update app.py
Browse files
app.py
CHANGED
@@ -19,6 +19,9 @@ st.write("提取餐廳數據,可視化區域分佈,並在地圖上顯示位
|
|
19 |
sheet_id = "1xUfnD1WCF5ldqECI8YXIko1gCpaDDCwTztL17kjI42U"
|
20 |
df = pd.read_csv(f"https://docs.google.com/spreadsheets/d/{sheet_id}/export?format=csv")
|
21 |
|
|
|
|
|
|
|
22 |
# Initialize Nominatim geocoder
|
23 |
geolocator = Nominatim(user_agent="my_unique_app/3.0")
|
24 |
|
@@ -42,8 +45,16 @@ def get_lat_lon(district):
|
|
42 |
st.error("地理編碼器遇到權限問題,請稍後再試。")
|
43 |
return None, None
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
# Apply geocoding to the dataframe
|
46 |
-
df['Region'] = df['
|
47 |
df['Latitude'], df['Longitude'] = zip(*df['Region'].apply(get_lat_lon))
|
48 |
|
49 |
# Display the DataFrame as a table at the top
|
@@ -141,7 +152,7 @@ for index, row in df.iterrows():
|
|
141 |
folium.Marker(
|
142 |
location=[row["Latitude"], row["Longitude"]],
|
143 |
popup=f"{row['Store Name']} (推薦度: {row['推薦度']})",
|
144 |
-
tooltip=row["
|
145 |
).add_to(marker_cluster)
|
146 |
heat_data.append([row["Latitude"], row["Longitude"], row["推薦度"]])
|
147 |
|
|
|
19 |
sheet_id = "1xUfnD1WCF5ldqECI8YXIko1gCpaDDCwTztL17kjI42U"
|
20 |
df = pd.read_csv(f"https://docs.google.com/spreadsheets/d/{sheet_id}/export?format=csv")
|
21 |
|
22 |
+
# Print column names
|
23 |
+
st.write("資料框的列名:", df.columns.tolist())
|
24 |
+
|
25 |
# Initialize Nominatim geocoder
|
26 |
geolocator = Nominatim(user_agent="my_unique_app/3.0")
|
27 |
|
|
|
45 |
st.error("地理編碼器遇到權限問題,請稍後再試。")
|
46 |
return None, None
|
47 |
|
48 |
+
# Check if required columns exist
|
49 |
+
required_columns = ['Address', 'Store Name', '推薦度']
|
50 |
+
missing_columns = [col for col in required_columns if col not in df.columns]
|
51 |
+
|
52 |
+
if missing_columns:
|
53 |
+
st.error(f"資料中缺少以下列:{', '.join(missing_columns)}")
|
54 |
+
st.stop()
|
55 |
+
|
56 |
# Apply geocoding to the dataframe
|
57 |
+
df['Region'] = df['Address'].apply(extract_region)
|
58 |
df['Latitude'], df['Longitude'] = zip(*df['Region'].apply(get_lat_lon))
|
59 |
|
60 |
# Display the DataFrame as a table at the top
|
|
|
152 |
folium.Marker(
|
153 |
location=[row["Latitude"], row["Longitude"]],
|
154 |
popup=f"{row['Store Name']} (推薦度: {row['推薦度']})",
|
155 |
+
tooltip=row["Address"]
|
156 |
).add_to(marker_cluster)
|
157 |
heat_data.append([row["Latitude"], row["Longitude"], row["推薦度"]])
|
158 |
|