-1
$\begingroup$

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?

$\endgroup$
1
  • $\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
1
$\begingroup$

You should add tranform():

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

Or you could use this directly:

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

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