Spaces:
Sleeping
Sleeping
| 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 |