I'm not sure if I understood your question clearly or not, but I assume instead of pd.NA or np.nan
in the columns you want to impute, you have "NaN"
(an object type). If that's the case, there's a way to work around it:
df_missing.iloc[:, 1:4] = df_missing.iloc[:, 1:4].replace({"NaN": np.nan})
By doing so, first you replace "NaN"
with np.nan
, and then you can use SimpleImputer:
imp = SimpleImputer(strategy = "mean")
imp = imp.fit(df_missing.iloc[:, 1:4])
I hope I understood your question right, and this solution helps you!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…