What is the solution to "Input contain NaN" when encoding categorical columns?

Viewed 56

I always get Input contains NaN whenever I run encoder.transform in my jupyter notebook. It works perfectly ok on google-colab.

encoder = OneHotEncoder(sparse=False,handle_unknown='ignore').fit(inputs_df[categorical_cols])
encoded_cols = list(encoder.get_feature_names(categorical_cols))
inputs_df[encoded_cols] = encoder.transform(inputs_df[categorical_cols])
1 Answers

Behavior env-dependent often means some dependencies have different versions installed.

It would help to add context when asking a question: lib used, etc. Aside from that, the solution is probably to avoid having NaNs in your input. Looks like sklearn, but not knowing the context, all I can do is point to google keywords that can help you. "sklearn remove NaN". "numpy nan_to_num".

Related