fix the the following code:

import pandas as pd

# Path to your UTF-16 encoded CSV file
csv_file = 'historical_data.csv'  # Change this to your actual file path

try:
    # Load the file using UTF-16 encoding
    df = pd.read_csv(csv_file, encoding='utf-16')

    # Strip any whitespace from column names
    df.columns = df.columns.str.strip()

    # Print column names for verification
    print(f"✅ Columns found: {df.columns.tolist()}")

    # Ensure required numeric columns are present
    required_columns = ['Open', 'High', 'Low', 'Close', 'Volume', 'Pair']
    for col in required_columns:
        if col not in df.columns:
            raise ValueError(f"Missing column: {col}")

    # Convert data types
    df[required_columns[:-1]] = df[required_columns[:-1]].astype(float)

    # Group by currency pair
    grouped = df.groupby('Pair')

    # Prepare summary list
    summary = []

    for pair, group in grouped:
        high = group['High'].max()
        low = group['Low'].min()
        max_close = group['Close'].max()
        min_close = group['Close'].min()
        mode_close = group['Close'].mode()
        most_common_close = mode_close.iloc[0] if not mode_close.empty else None
        frequency = group['Close'].value_counts().get(most_common_close, 0)
        count = len(group)

        summary.append({
            'Pair': pair,
            'Highest High': high,
            'Lowest Low': low,
            'Highest Close': max_close,
            'Lowest Close': min_close,
            'Most Frequent Close': most_common_close,
            'Frequency of Most Frequent Close': frequency,
            'Data Points': count
        })

    # Create summary DataFrame
    summary_df = pd.DataFrame(summary)

    # Print to console
    print("\n📊 Forex Summary Statistics:\n")
    print(summary_df)

    # Save to CSV
    output_file = 'forex_analysis_summary.csv'
    summary_df.to_csv(output_file, index=False)
    print(f"\n✅ Summary exported to '{output_file}'")

except Exception as e:
    print(f"\n❌ Error: {e}")


error:
import pandas as pd

# Path to your UTF-16 encoded CSV file
csv_file = 'historical_data.csv'  # Change this to your actual file path

try:
    # Load the file using UTF-16 encoding
    df = pd.read_csv(csv_file, encoding='utf-16')

    # Strip any whitespace from column names
    df.columns = df.columns.str.strip()

    # Print column names for verification
    print(f"✅ Columns found: {df.columns.tolist()}")

    # Ensure required numeric columns are present
    required_columns = ['Open', 'High', 'Low', 'Close', 'Volume', 'Pair']
    for col in required_columns:
        if col not in df.columns:
            raise ValueError(f"Missing column: {col}")

    # Convert data types
    df[required_columns[:-1]] = df[required_columns[:-1]].astype(float)

    # Group by currency pair
    grouped = df.groupby('Pair')

    # Prepare summary list
    summary = []

    for pair, group in grouped:
        high = group['High'].max()
        low = group['Low'].min()
        max_close = group['Close'].max()
        min_close = group['Close'].min()
        mode_close = group['Close'].mode()
        most_common_close = mode_close.iloc[0] if not mode_close.empty else None
        frequency = group['Close'].value_counts().get(most_common_close, 0)
        count = len(group)

        summary.append({
            'Pair': pair,
            'Highest High': high,
            'Lowest Low': low,
            'Highest Close': max_close,
            'Lowest Close': min_close,
            'Most Frequent Close': most_common_close,
            'Frequency of Most Frequent Close': frequency,
            'Data Points': count
        })

    # Create summary DataFrame
    summary_df = pd.DataFrame(summary)

    # Print to console
    print("\n📊 Forex Summary Statistics:\n")
    print(summary_df)

    # Save to CSV
    output_file = 'forex_analysis_summary.csv'
    summary_df.to_csv(output_file, index=False)
    print(f"\n✅ Summary exported to '{output_file}'")

except Exception as e:
    print(f"\n❌ Error: {e}")


Data format :
Time	Open	High	Low	Close	Volume	Pair	Timeframe
2025.05.22 16:30:00	1.12956	1.12957	1.12933	1.12955	113	EURUSD.Z	PERIOD_M1
2025.05.22 16:31:00	1.12954	1.12978	1.12947	1.12966	117	EURUSD.Z	PERIOD_M1
2025.05.22 16:32:00	1.12969	1.12982	1.12932	1.12933	111	EURUSD.Z	PERIOD_M1
2025.05.22 16:33:00	1.12932	1.12945	1.129	1.12941	154	EURUSD.Z	PERIOD_M1
2025.05.22 16:34:00	1.12944	1.1296	1.12934	1.12958	66	EURUSD.Z	PERIOD_M1
2025.05.22 16:30:00	1.34151	1.34166	1.3413	1.34156	153	GBPUSD.Z	PERIOD_M1
2025.05.22 16:31:00	1.34155	1.34187	1.34154	1.34177	117	GBPUSD.Z	PERIOD_M1
2025.05.22 16:32:00	1.34182	1.34188	1.34134	1.34135	130	GBPUSD.Z	PERIOD_M1
2025.05.22 16:33:00	1.34136	1.34141	1.34089	1.34141	168	GBPUSD.Z	PERIOD_M1
2025.05.22 16:34:00	1.34143	1.34154	1.34132	1.34152	102	GBPUSD.Z	PERIOD_M1
2025.05.22 16:30:00	143.623	143.653	143.617	143.617	191	USDJPY.Z	PERIOD_M1
2025.05.22 16:31:00	143.618	143.633	143.587	143.623	164	USDJPY.Z	PERIOD_M1
2025.05.22 16:32:00	143.618	143.653	143.609	143.639	177	USDJPY.Z	PERIOD_M1
2025.05.22 16:33:00	143.639	143.665	143.562	143.562	172	USDJPY.Z	PERIOD_M1
2025.05.22 16:34:00	143.562	143.585	143.538	143.55	147	USDJPY.Z	PERIOD_M1
2025.05.22 16:30:00	0.64139	0.64149	0.64127	0.64148	95	AUDUSD.Z	PERIOD_M1
2025.05.22 16:31:00	0.64149	0.64164	0.64148	0.64164	103	AUDUSD.Z	PERIOD_M1
2025.05.22 16:32:00	0.64164	0.64171	0.64132	0.64135	79	AUDUSD.Z	PERIOD_M1
2025.05.22 16:33:00	0.64133	0.64133	0.64113	0.64116	115	AUDUSD.Z	PERIOD_M1
2025.05.22 16:34:00	0.64117	0.64128	0.64115	0.64128	55	AUDUSD.Z	PERIOD_M1
2025.05.22 16:30:00	162.245	162.261	162.232	162.239	215	EURJPY.Z	PERIOD_M1
2025.05.22 16:31:00	162.24	162.268	162.212	162.257	171	EURJPY.Z	PERIOD_M1
2025.05.22 16:32:00	162.253	162.262	162.217	162.217	232	EURJPY.Z	PERIOD_M1
2025.05.22 16:33:00	162.217	162.219	162.145	162.145	251	EURJPY.Z	PERIOD_M1
2025.05.22 16:34:00	162.146	162.162	162.137	162.157	142	EURJPY.Z	PERIOD_M1
2025.05.22 16:30:00	192.672	192.702	192.665	192.678	364	GBPJPY.Z	PERIOD_M1
2025.05.22 16:31:00	192.679	192.718	192.66	192.712	308	GBPJPY.Z	PERIOD_M1
2025.05.22 16:32:00	192.704	192.721	192.695	192.695	101	GBPJPY.Z	PERIOD_M1
2025.05.22 16:30:00	1.38826	1.38851	1.38814	1.38818	96	USDCAD.Z	PERIOD_M1
2025.05.22 16:31:00	1.38818	1.38823	1.38789	1.38791	52	USDCAD.Z	PERIOD_M1
2025.05.22 16:32:00	1.38791	1.38839	1.3879	1.38835	70	USDCAD.Z	PERIOD_M1
2025.05.22 16:33:00	1.38836	1.3886	1.38836	1.38849	69	USDCAD.Z	PERIOD_M1
2025.05.22 16:34:00	1.38849	1.38849	1.3882	1.38822	66	USDCAD.Z	PERIOD_M1
2025.05.22 16:30:00	0.82708	0.82731	0.82707	0.82722	94	USDCHF.Z	PERIOD_M1
2025.05.22 16:31:00	0.82725	0.8273	0.82711	0.8272	113	USDCHF.Z	PERIOD_M1
2025.05.22 16:32:00	0.82717	0.82753	0.82713	0.82751	75	USDCHF.Z	PERIOD_M1
2025.05.22 16:33:00	0.82751	0.8277	0.82729	0.8273	108	USDCHF.Z	PERIOD_M1
2025.05.22 16:34:00	0.82729	0.82736	0.82711	0.82716	73	USDCHF.Z	PERIOD_M1