Lashtw commited on
Commit
8233f0c
·
verified ·
1 Parent(s): a3ea68d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -77,9 +77,24 @@ def main():
77
  df = load_data(uploaded_file)
78
 
79
  if df is not None:
 
 
 
80
  # 選擇要比較的欄位
81
  numeric_columns = df.select_dtypes(include=[np.number]).columns.tolist()
82
- selected_columns = st.multiselect('選擇要比較的欄位', numeric_columns, default=['國文', '英文', '數學'])
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  if selected_columns:
85
  # 準備雷達圖數據
 
77
  df = load_data(uploaded_file)
78
 
79
  if df is not None:
80
+ # 定義預期的欄位列表
81
+ expected_columns = ['國文', '英文', '數學', '自科', '地理', '歷史', '公民', '總平均', '社會']
82
+
83
  # 選擇要比較的欄位
84
  numeric_columns = df.select_dtypes(include=[np.number]).columns.tolist()
85
+
86
+ # 篩選出存在的欄位
87
+ available_columns = [col for col in expected_columns if col in numeric_columns]
88
+
89
+ # 如果沒有可用的預期欄位,則使用所有數值欄位
90
+ if not available_columns:
91
+ available_columns = numeric_columns
92
+
93
+ selected_columns = st.multiselect(
94
+ '選擇要比較的欄位',
95
+ numeric_columns,
96
+ default=available_columns
97
+ )
98
 
99
  if selected_columns:
100
  # 準備雷達圖數據