df_2 is data frame

My code:

from sklearn.impute import SimpleImputer
    impute = SimpleImputer(missing_values=np.NaN,strategy='mean')
    df_2.iloc[:,2:9] = impute.fit(df_2.iloc[:,2:9])

I got error:

TypeError: float() argument must be a string or a number, not 'SimpleImputer'

I do not know why can anyone help me?

  • $\begingroup$ Please edit you question for more answers. And also check your problem on stackoverflow, as there is high possibility that this kind of question would have been asked there. $\endgroup$
    – Ankit Seth
    Aug 25 at 17:11

You should add tranform():


Or you could use this directly:

df_2.iloc[:,2:9] = imputer.fit_transform(df_2.iloc[:,2:9])

Not the answer you're looking for? Browse other questions tagged or ask your own question.