Skip to content

Commit

Permalink
Fix excel logging
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarojhahn committed Oct 29, 2024
1 parent 1cd1714 commit e57ecf5
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pathways/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,16 @@ def log_mc_parameters_to_excel(
):
export_path = STATS_DIR / f"{model}_{scenario}_{year}.xlsx"

mode = "a" if export_path.exists() else "w"
if export_path.exists():
mode = "a"
if_sheet_exists = "replace"
else:
mode = "w"
if_sheet_exists = None # No need for if_sheet_exists in write mode

with pd.ExcelWriter(
export_path, engine="openpyxl", mode=mode, if_sheet_exists="replace"
) as writer:
with pd.ExcelWriter(export_path, engine="openpyxl", mode=mode, if_sheet_exists=if_sheet_exists) as writer:
empty_df = pd.DataFrame() # Empty DataFrame for clearing purposes
for sheet in [
"Indices mapping",
"Monte Carlo values",
"Technology shares",
"Total impacts",
]:
for sheet in ["Indices mapping", "Monte Carlo values", "Technology shares", "Total impacts"]:
empty_df.to_excel(writer, sheet_name=sheet, index=False)

df_sum_impacts = pd.DataFrame()
Expand Down

0 comments on commit e57ecf5

Please sign in to comment.