I'm trying to impute 5 columns in a dataset, each column however do not have any blanks in them, I need to impute rows having 0 to mean/median, I tried the following 2 alternatives independently as shown below
from sklearn.impute import SimpleImputer
impute = SimpleImputer(missing_values=0,strategy='mean')
impute.fit_transform(train[['Glucose','BloodPressure','SkinThickness','Insulin','BMI']])
AND
train["Glucose"].fillna(train["Glucose"].mean(), inplace=True)
To cross check i tried to find unique values in each column train['Glucose'].unique()
, after each of the alternatives to find if there are any 0 after imputing.
Output does shows 0 as under, suggesting the above 2 methods failed to work.
Output
array([148, 85, 183, 89, 137, 116, 78, 115, 197, 125, 110, 168, 139,
189, 166, 100, 118, 107, 103, 126, 99, 196, 119, 143, 147, 97,
145, 117, 109, 158, 88, 92, 122, 138, 102, 90, 111, 180, 133,
106, 171, 159, 146, 71, 105, 101, 176, 150, 73, 187, 84, 44,
141, 114, 95, 129, 79, **0**, 62, 131, 112, 113, 74, 83, 136,
80, 123, 81, 134, 142, 144, 93, 163, 151, 96, 155, 76, 160,
124, 162, 132, 120, 173, 170, 128, 108, 154, 57, 156, 153, 188,
152, 104, 87, 75, 179, 130, 194, 181, 135, 184, 140, 177, 164,
91, 165, 86, 193, 191, 161, 167, 77, 182, 157, 178, 61, 98,
127, 82, 72, 172, 94, 175, 195, 68, 186, 198, 121, 67, 174,
199, 56, 169, 149, 65, 190], dtype=int64)
I would really appreciate if someone could guide me where my code is wrong or any other way to impute.