loan-intelligence-v1 / src /data_loader.py
sahiljadhav1221
Initial commit - Loan Prediction Project
e93c178
raw
history blame contribute delete
586 Bytes
import pandas as pd
def load_data(path):
try:
# read csv file
df = pd.read_csv(path)
# fill missing numeric values with mean
for col in df.select_dtypes(include=['int64', 'float64']).columns:
df[col].fillna(df[col].mean(), inplace=True)
# fill missing categorical values with most frequent value
for col in df.select_dtypes(include=['object']).columns:
df[col].fillna(df[col].mode()[0], inplace=True)
return df
except:
# return None if file not found or error occurs
return None