from __future__ import annotations from pathlib import Path import pandas as pd def to_excel_safely(df: pd.DataFrame, path: Path) -> None: path.parent.mkdir(parents=True, exist_ok=True) df.to_excel(path, index=False)