title: ML Code throws value error when transforming data
body: <p>Data source can be found <a href="https://drive.google.com/file/d/14-VaJqtkAy4A0BfEwsHhLKfn887Z-7hF/view?usp=sharing" rel="nofollow noreferrer">here</a>.</p>
  <p>Hello all,</p>
  <p>I've hit a stumbling block in some code I'm writing because the fit_transform method continuously fails. It throws this error:</p>
  <pre><code>Traceback (most recent call last):
  
    File &quot;/home/user/Datasets/CSVs/Working/Playstore/untitled0.py&quot;, line 18, in &lt;module&gt;
      data = data[oh_cols].apply(oh.fit_transform)
  
    File &quot;/usr/lib/python3.8/site-packages/pandas/core/frame.py&quot;, line 7547, in apply
      return op.get_result()
  
    File &quot;/usr/lib/python3.8/site-packages/pandas/core/apply.py&quot;, line 180, in get_result
      return self.apply_standard()
  
    File &quot;/usr/lib/python3.8/site-packages/pandas/core/apply.py&quot;, line 255, in apply_standard
      results, res_index = self.apply_series_generator()
  
    File &quot;/usr/lib/python3.8/site-packages/pandas/core/apply.py&quot;, line 284, in apply_series_generator
      results[i] = self.f(v)
  
    File &quot;/usr/lib/python3.8/site-packages/sklearn/preprocessing/_encoders.py&quot;, line 410, in fit_transform
      return super().fit_transform(X, y)
  
    File &quot;/usr/lib/python3.8/site-packages/sklearn/base.py&quot;, line 690, in fit_transform
      return self.fit(X, **fit_params).transform(X)
  
    File &quot;/usr/lib/python3.8/site-packages/sklearn/preprocessing/_encoders.py&quot;, line 385, in fit
      self._fit(X, handle_unknown=self.handle_unknown)
  
    File &quot;/usr/lib/python3.8/site-packages/sklearn/preprocessing/_encoders.py&quot;, line 74, in _fit
      X_list, n_samples, n_features = self._check_X(X)
  
    File &quot;/usr/lib/python3.8/site-packages/sklearn/preprocessing/_encoders.py&quot;, line 43, in _check_X
      X_temp = check_array(X, dtype=None)
  
    File &quot;/usr/lib/python3.8/site-packages/sklearn/utils/validation.py&quot;, line 73, in inner_f
      return f(**kwargs)
  
    File &quot;/usr/lib/python3.8/site-packages/sklearn/utils/validation.py&quot;, line 620, in check_array
      raise ValueError(
  
  ValueError: Expected 2D array, got 1D array instead:
  array=['Everyone' 'Everyone' 'Everyone' ... 'Everyone' 'Mature 17+' 'Everyone'].
  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.
  </code></pre>
  <p>To put short:</p>
  <pre><code>ValueError: Expected 2D array, got 1D array instead:
  </code></pre>
  <p>I've done some searching on this online and arrived at a few potential solutions, but they didn't seem to work.</p>
  <p>Here's my code:</p>
  <pre><code>import pandas as pd
  from sklearn.preprocessing import OneHotEncoder
  from category_encoders import CatBoostEncoder,CountEncoder,TargetEncoder
  
  data = pd.read_csv(&quot;/home/user/Datasets/CSVs/Working/Playstore/data.csv&quot;)
  
  
  oh = OneHotEncoder()
  cb = CatBoostEncoder()
  ce = CountEncoder()
  te = TargetEncoder()
  
  obj = [i for i in data if data[i].dtypes==&quot;object&quot;]
  unique = dict(zip(list(obj),[len(data[i].unique()) for i in obj]))
  oh_cols = [i for i in unique if unique[i] &lt; 100]
  te_cols = [i for i in unique if unique[i] &gt; 100]
  
  data = data[oh_cols].apply(oh.fit_transform)
  </code></pre>
  <p>It throws the aforementioned error. A solution I saw advised me to use <code>.values</code> when transforming the data and I tried the following:</p>
  <p><code>data = data[oh_cols].values.apply(oh.fit_transform)</code></p>
  <p><code>data = data[oh_cols].apply(oh.fit_transform).values</code></p>
  <pre><code>encoding = np.array(data[oh_cols])
  encoding.apply(oh.fit_transform)
  </code></pre>
  <p>The first and the third threw the same error which is below,:</p>
  <pre><code>AttributeError: 'numpy.ndarray' object has no attribute 'apply'
  </code></pre>
  <p>While the second threw the first error I mentioned again:</p>
  <pre><code>ValueError: Expected 2D array, got 1D array instead:
  </code></pre>
  <p>I'm honestly stumped and I'm not sure where to go from here. The Kaggle exercise I learnt this from went smoothly, but for some reason things never do when I try my hand at things myself.</p>