-1

ValueError: Input contains NaN i have run

from sklearn.preprocessing import OrdinalEncoderfrom
data_.iloc[:,1:-1] = OrdinalEncoder().fit_transform(data_.iloc[:,1:-1])

here is data_

    Age     Sex Embarked  Survived
0  22.0    male        S         0
1  38.0  female        C         2
2  26.0  female        S         2
3  35.0  female        S         2
4  35.0    male        S         0
gtomer
  • 5,643
  • 1
  • 10
  • 21
xyssyxxys
  • 1
  • 1

1 Answers1

0

Before doing some processor, you have always have to to preprocess the data and make a few summary of how your data is. In concrete, the error you obtained is telling you that you have NaN values. To check it, try this command:

df.isnull().any().any()

If the output is TRUE, you have NaN values. You can run the next command if you want to know where this NaN values are:

df.isnull().any()

Then, you will know in which column are your NaN values.

Once you know you have NaN values, you have to preprocess them (eliminate, fill,... whatever you believe is the best option). The link gtomer commented is a nice resource.

Alex Serra Marrugat
  • 1,849
  • 1
  • 4
  • 14