原始漁貨交易檔案來源是執行"條件過濾漁產品交易的資料儲存到EXCEL檔案中"。
ChatGPT產生的程式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import pandas as pd
# 讀取原始 Excel 檔案
file_path = "AquaticTransData.xlsx"
df = pd.read_excel(file_path)
# 建立樞紐分析表:以市場名稱與魚貨名稱為索引,統計交易量總和與平均價平均
pivot_table = pd.pivot_table(
df,
index=['市場名稱', '魚貨名稱'],
values=['交易量', '平均價'],
aggfunc={'交易量': 'sum', '平均價': 'mean'}
)
# 重設索引方便輸出
pivot_table.reset_index(inplace=True)
# 匯出為新的 Excel 檔案
output_file_path = "AquaticTrans_PivotTable.xlsx"
pivot_table.to_excel(output_file_path, index=False)
print("已成功產出樞紐分析表:", output_file_path)
|
執行結果:

沒有留言:
張貼留言