File size: 548 Bytes
31801e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import pandas as pd

def load_data(filepath):
    # Check the file extension and load the file accordingly
    if filepath.endswith('.csv'):
        df = pd.read_csv(filepath)
    elif filepath.endswith('.xlsx') or filepath.endswith('.xls'):
        df = pd.read_excel(filepath)
    else:
        raise ValueError("Unsupported file format: Please provide a .csv or .xlsx file")
    
    # Convert all string values to lowercase and remove spaces
    df = df.map(lambda x: x.lower().replace(" ", "") if isinstance(x, str) else x)
    
    return df