Spaces:
Paused
Paused
Update app.py
Browse files
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 |
|