Home > Software engineering >  ValueError: Input contains NaN
ValueError: Input contains NaN

Time:09-21

I'm having this kind of error and I really don't know what to do, please help me out with this it's say NaN which I dont have an idea what it it enter image description here

CodePudding user response:

you need to get rid of infinite and null values. try:

df = df.replace([np.inf, -np.inf], np.nan).fillna(99999)

#or
df.replace([np.inf, -np.inf], np.nan).dropna() 

#if needed:
df = df.reset_index() 

CodePudding user response:

You can use the imputation function from sklearn to fill nan values.

https://scikit-learn.org/stable/modules/impute.html

from sklearn.impute import SimpleImputer
imp = SimpleImputer(missing_values=np.nan, strategy='mean')
values = imp.fit([[1, 2], [np.nan, 3], [7, 6]])
  • Related