Rozeeeee commited on
Commit
f573f99
·
verified ·
1 Parent(s): 86f7cfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -10,7 +10,7 @@ import json # 用於解析 JSON 文件
10
  # Streamlit UI 標題
11
  st.title("Booking.com 多項目數據抓取和視覺化展示")
12
 
13
- # 定義 URL 列表(包含所有提供的 URL)
14
  urls = [
15
  "https://www.booking.com/hotel/it/appartamento-via-genova-roma.zh-tw.html",
16
  "https://www.booking.com/hotel/it/giulia-39-s-coliseum.zh-tw.html",
@@ -104,11 +104,13 @@ if st.button("上傳數據至 Google Sheets") and data:
104
 
105
  # 數據視覺化
106
  st.header("數據視覺化")
107
- if not df.empty:
108
- # 確保評分可以轉換為數字
109
- df['評分'] = pd.to_numeric(df['評分'], errors='coerce')
110
  # 使用 Plotly 繪製條形圖
111
- fig = px.bar(df, x='標題', y='評分', title="Booking.com 評分比較", labels={'標題': '酒店標題', '評分': '評分'})
 
 
112
  fig.update_layout(xaxis_title="酒店標題", yaxis_title="評分", xaxis_tickangle=-45)
113
  st.plotly_chart(fig)
114
  else:
 
10
  # Streamlit UI 標題
11
  st.title("Booking.com 多項目數據抓取和視覺化展示")
12
 
13
+ # 合併的 URL 列表
14
  urls = [
15
  "https://www.booking.com/hotel/it/appartamento-via-genova-roma.zh-tw.html",
16
  "https://www.booking.com/hotel/it/giulia-39-s-coliseum.zh-tw.html",
 
104
 
105
  # 數據視覺化
106
  st.header("數據視覺化")
107
+ if data:
108
+ # 提取數字評分
109
+ df['數字評分'] = df['評分'].str.extract(r'評分:(\d+\.\d+)').astype(float)
110
  # 使用 Plotly 繪製條形圖
111
+ fig = px.bar(df, x='標題', y='數字評分', title="Booking.com 評分比較",
112
+ labels={'標題': '酒店標題', '數字評分': '評分'},
113
+ text='數字評分')
114
  fig.update_layout(xaxis_title="酒店標題", yaxis_title="評分", xaxis_tickangle=-45)
115
  st.plotly_chart(fig)
116
  else: