CosmickVisions commited on
Commit
3f24c82
·
verified ·
1 Parent(s): da4d621

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -360,16 +360,23 @@ elif app_mode == "Smart Cleaning":
360
  if missing_value_method == "Drop Missing":
361
  df = df.dropna(subset=cols) # Drop rows with missing values in selected columns
362
  cleaning_actions.append(f"Dropped missing values in selected columns")
363
- elif missing_value_method == "Mean/Median/Mode":
364
- # Imputation logic here, added to perform the imputation in multiple columns
 
 
 
365
  for col in cols:
366
  if df[col].isnull().any(): # Check if missing values exist before imputing
367
  if pd.api.types.is_numeric_dtype(df[col]):
368
- df[col] = df[col].fillna(df[col].mean())
369
- else: # Impute strings with mode
 
 
 
 
 
370
  df[col] = df[col].fillna(df[col].mode()[0])
371
-
372
- cleaning_actions.append(f"Applied Mean/Median/Mode imputation on {cols}")
373
 
374
  elif missing_value_method == "KNN Imputation":
375
  from sklearn.impute import KNNImputer
 
360
  if missing_value_method == "Drop Missing":
361
  df = df.dropna(subset=cols) # Drop rows with missing values in selected columns
362
  cleaning_actions.append(f"Dropped missing values in selected columns")
363
+ elif missing_value_method == "Mean/Median/Mode":
364
+ # Allow the user to select the specific imputation method
365
+ imputation_choice = st.radio("Select Imputation Method", ["Mean", "Median", "Mode"], horizontal=True)
366
+
367
+ # Imputation logic here, added to perform the imputation in multiple columns
368
  for col in cols:
369
  if df[col].isnull().any(): # Check if missing values exist before imputing
370
  if pd.api.types.is_numeric_dtype(df[col]):
371
+ if imputation_choice == "Mean":
372
+ df[col] = df[col].fillna(df[col].mean())
373
+ elif imputation_choice == "Median":
374
+ df[col] = df[col].fillna(df[col].median())
375
+ elif imputation_choice == "Mode":
376
+ df[col] = df[col].fillna(df[col].mode()[0])
377
+ else: # Impute strings with mode
378
  df[col] = df[col].fillna(df[col].mode()[0])
379
+ cleaning_actions.append(f"Applied Mean/Median/Mode imputation on {cols}")
 
380
 
381
  elif missing_value_method == "KNN Imputation":
382
  from sklearn.impute import KNNImputer