File size: 789 Bytes
2c0c586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# src/data_loader.py
import pandas as pd

def load_data(file_path: str) -> pd.DataFrame | None:
    try:
        if file_path.endswith('.csv'):
            df = pd.read_csv(file_path)
        elif file_path.endswith(('.xls', '.xlsx')):
            df = pd.read_excel(file_path)
        else:
            print("Unsupported file format.")
            return None

        # Basic validation: Ensure 'Department' column exists.
        # Subject-specific columns will be handled by the preprocessor.
        if 'Department'  not in df.columns:
            print("Missing required column: 'Department'")
            return None

        print("Data loaded successfully (wide format).")
        return df
    except Exception as e:
        print(f"Error loading data: {e}")
        return None