import pandas as pd

def swap_fp_fn(excel_path, output_path):
    # Load the Excel file
    excel_data = pd.ExcelFile(excel_path)

    # Create a Pandas ExcelWriter using openpyxl engine
    with pd.ExcelWriter(output_path, engine='openpyxl') as writer:
        # Iterate through each sheet in the Excel file
        for sheet_name in excel_data.sheet_names:
            # Read the sheet into a DataFrame
            df = excel_data.parse(sheet_name)

            # Check if the columns 'FP' and 'FN' exist in the DataFrame
            if 'FP' in df.columns and 'FN' in df.columns:
                # Swap the 'FP' and 'FN' columns
                df['FP'], df['FN'] = df['FN'].copy(), df['FP'].copy()

            # Save the modified DataFrame back to the sheet in the new Excel file
            df.to_excel(writer, sheet_name=sheet_name, index=False)

    print(f"Swapped FP and FN columns in '{excel_path}' and saved to '{output_path}'.")

# Path to your existing Excel file
input_excel_path = '../output_test/testing_tuned_models.xlsx'
# Path where the modified Excel file will be saved (can be the same as input_excel_path)
output_excel_path = '../output_test/testing_tuned_models_fixed.xlsx'

# Call the function with the file paths
swap_fp_fn(input_excel_path, output_excel_path)