Untitled
unknown
python
8 months ago
1.3 kB
2
Indexable
Never
book = load_workbook(output_path) with pd.ExcelWriter(output_path, mode='a', engine='openpyxl', if_sheet_exists='overlay') as writer: grouped = MDF_table.groupby('scope') for scope, group in grouped: scope_cashflow_table = CashFlowTable() for _, row in group.iterrows(): cashflow_table = specific_policies[(row['年期'], row['年齡'], row['性別'])].profit_testing( channel=row['通路'], premium_discount=row['折扣'], input_type=row['input類型'], average_premium=row['平均保費(萬元)'] * 10000, average_SA=row['平均保額(萬元)'] * 10000, get_cashflow=True, run_pricing=False, NP_table=df_NP, RV_table=df_RV, RV_L_table=df_RV_L, RV_PA_table=df_RV_PA)[1] scope_cashflow_table.aggregate(cashflow_table) df = pd.DataFrame(scope_cashflow_table.cashflows) sheet_name = f'Scope {scope}' if sheet_name in book.sheetnames: del book[sheet_name] sheet = book.create_sheet(sheet_name) sheet['B1'] = '年度' for i in range(1, 36): sheet.cell(row=1, column=i + 1, value=f'({i})') df.to_excel(writer, sheet_name=sheet_name, startrow=1) writer.save()
Leave a Comment