deneve07 commited on
Commit
a2eaf32
·
verified ·
1 Parent(s): 2000fa5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -0
app.py CHANGED
@@ -77,6 +77,10 @@ def generate_standard_excel(selected_components):
77
  # 自動判斷數量欄位名稱
78
  qty_col = '數量(顆)' if '數量(顆)' in df_filtered.columns else [col for col in df_filtered.columns if '數量' in col][0]
79
 
 
 
 
 
80
  # 進行樞紐分析 (Pivot Table)
81
  pivot_df = df_filtered.groupby(['成分', '劑型', '劑量', '廠商', '年度'])[qty_col].sum().unstack(fill_value=0)
82
 
 
77
  # 自動判斷數量欄位名稱
78
  qty_col = '數量(顆)' if '數量(顆)' in df_filtered.columns else [col for col in df_filtered.columns if '數量' in col][0]
79
 
80
+ # 【新增:強制將數量欄位轉換為數值型態,並移除非數字字元】
81
+ df_filtered[qty_col] = df_filtered[qty_col].astype(str).str.replace(',', '').str.strip()
82
+ df_filtered[qty_col] = pd.to_numeric(df_filtered[qty_col], errors='coerce').fillna(0)
83
+
84
  # 進行樞紐分析 (Pivot Table)
85
  pivot_df = df_filtered.groupby(['成分', '劑型', '劑量', '廠商', '年度'])[qty_col].sum().unstack(fill_value=0)
86