# Error when using simple imputer to impute nan values? [closed]

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?

• 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. Aug 25 at 17:11

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

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