Update app.py
Browse files
app.py
CHANGED
|
@@ -27,12 +27,20 @@ agent = CodeAgent(
|
|
| 27 |
)
|
| 28 |
|
| 29 |
# Data cleaning function
|
|
|
|
|
|
|
| 30 |
def clean_data(df):
|
| 31 |
df = df.dropna(how='all', axis=1).dropna(how='all', axis=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
df = df.fillna(df.mean(numeric_only=True))
|
| 33 |
-
df = df.select_dtypes(include=[np.number])
|
| 34 |
return df
|
| 35 |
|
|
|
|
| 36 |
# Global dataframe
|
| 37 |
df_global = None
|
| 38 |
|
|
|
|
| 27 |
)
|
| 28 |
|
| 29 |
# Data cleaning function
|
| 30 |
+
from sklearn.preprocessing import LabelEncoder
|
| 31 |
+
|
| 32 |
def clean_data(df):
|
| 33 |
df = df.dropna(how='all', axis=1).dropna(how='all', axis=0)
|
| 34 |
+
|
| 35 |
+
# Encode categorical features
|
| 36 |
+
for col in df.select_dtypes(include='object').columns:
|
| 37 |
+
df[col] = df[col].astype(str)
|
| 38 |
+
df[col] = LabelEncoder().fit_transform(df[col])
|
| 39 |
+
|
| 40 |
df = df.fillna(df.mean(numeric_only=True))
|
|
|
|
| 41 |
return df
|
| 42 |
|
| 43 |
+
|
| 44 |
# Global dataframe
|
| 45 |
df_global = None
|
| 46 |
|