title: One Hot Encoding a single column
body: <p>I am trying to use one hot encoder on the target column('Species') in the Iris dataset.</p>
  
  <p>But I am getting the following errors:</p>
  
  <blockquote>
    <p>ValueError: Expected 2D array, got 1D array instead:</p>
    
    <p>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.</p>
  </blockquote>
  
  <pre><code>Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm    Species
  0   1   5.1 3.5 1.4         0.2     Iris-setosa
  1   2   4.9 3.0 1.4         0.2     Iris-setosa
  2   3   4.7 3.2 1.3         0.2     Iris-setosa
  3   4   4.6 3.1 1.5         0.2     Iris-setosa
  4   5   5.0 3.6 1.4         0.2     Iris-setosa
  </code></pre>
  
  <p>I did google the issue and i found that most of the scikit learn estimators need a 2D array rather than a 1D array.</p>
  
  <p>At the same time, I also found that we can try passing the dataframe with its index to encode single columns, but it didn't work</p>
  
  <pre><code>onehotencoder = OneHotEncoder(categorical_features=[df.columns.tolist().index('pattern_id')
  X = dataset.iloc[:,1:5].values
  y = dataset.iloc[:, 5].values
  
  from sklearn.preprocessing import LabelEncoder, OneHotEncoder
  
  labelencoder= LabelEncoder()
  y = labelencoder.fit_transform(y)
  
  
  onehotencoder = OneHotEncoder(categorical_features=[0])
  y = onehotencoder.fit_transform(y)
  </code></pre>
  
  <p>I am trying to encode a single categorical column and split into multiple columns (the way the encoding usually works)</p>