0

I'm trying to use OneHot encoder in the following series:

1       redução
2       redução
3       redução
4       redução
         ...   
1969     normal
1970     normal
1971     normal
1972     normal
1973     normal
Length: 1974, dtype: object

But it's returning me the following error

ValueError: Expected 2D array, got 1D array instead:
array=['redução' 'redução' 'redução' ... 'normal' 'normal' 'normal'].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

I already tried the approach above and also tried np.array(s.values.tolist()) and it also didn't work, can anyone help me with this please?

This series has actually 3 unique values, that's why I'm trying to use OneHotEncoder

1 Answer 1

3

I use the following to one hot encode my pandas data frames:

df_dummy = pd.get_dummies(df['col'])

df = pd.concat([df, df_dummy], axis=1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.