all,
i have np.nans and np.infs in my data. i would like to replace these with 0's however when i do the below i get the following error:
imputer = SimpleImputer(missing_values=np.nan, strategy='constant', fill_value=0)
features_to_impute = data_fe.columns.tolist()
data_fe[features_to_impute] = pd.DataFrame(imputer.fit_transform(data_fe[features_to_impute]),
columns=features_to_impute)
ValueError: Input contains infinity or a value too large for dtype('float64').
not sure how to deal with this, does anybody know how i can go around this and also impute the infs as well?
If you want to replace both
np.nan
andnp.inf
to0
, just usenp.nan_to_num
Example:
So, in your case, just pass the selected columns of dataframe to
np.nan_to_num