title: How to add a second feature to a countvectorized feature using sklearn?
body: <p>I have 3 columns in my data set:</p>
  
  <p><strong>Review</strong>: A product review</p>
  
  <p><strong>Type</strong>: A category or product type</p>
  
  <p><strong>Cost</strong>: How much the product cost</p>
  
  <p>This is a multiclass problem, with Type as the target variable. There are 64 different Types of products in this dataset.</p>
  
  <p><strong>Review</strong> and <strong>Cost</strong> are my two features.</p>
  
  <p>I've split the data into 4 sets with the <strong>Type</strong> variable removed:</p>
  
  <pre><code>X = data.drop('type', axis = 1)
  y = data.type
  X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)
  </code></pre>
  
  <p>For <strong>Review</strong>, I am using the following to vectorize it:</p>
  
  <pre><code>vect = CountVectorizer(stop_words = stop)
  X_train_dtm = vect.fit_transform(X_train.review)
  </code></pre>
  
  <p>Here's where I am stuck! </p>
  
  <p>In order to run the model I need to have both my features in the training set, however, since X_train_dtm is a sparse matrix, I am unsure as to how I concatenate my pandas series <strong>Cost</strong> feature to that sparse matrix.  Since the data is already numerical for the <strong>Cost</strong>, I don't think that I need to transform it, which is why I have not used something like "FeatureUnion" which combines 2 transformed features.  </p>
  
  <p>Any help would be appreciated!!</p>
  
  <p>Example data:</p>
  
  <pre><code>| Review           | Cost        | Type         |
  |:-----------------|------------:|:------------:|
  | This is a review |        200  |     Toy     
  | This is a review |        100  |     Toy    
  | This is a review |        800  |  Electronics     
  | This is a review |         35  |     Home      
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>After applying tarashypka's solution I was able to rid add the second feature to the X_train_dtm. However, I am getting an error when attempting to run the same on the test set:</p>
  
  <p>from scipy.sparse import hstack</p>
  
  <pre><code>vect = CountVectorizer(stop_words = stop)
  X_train_dtm = vect.fit_transform(X_train.review)
  prices = X_train.prices.values[:,None]
  X_train_dtm = hstack((X_train_dtm, prices))
  
  #Works perfectly for the training set above
  #But when I run with test set I get the following error
  X_test_dtm = vect.transform(X_test)
  prices_test = X_test.prices.values[:,None]
  X_test_dtm = hstack((X_test_dtm, prices_test))
  
  Traceback (most recent call last):
  
    File "&lt;ipython-input-10-b2861d63b847&gt;", line 8, in &lt;module&gt;
      X_test_dtm = hstack((X_test_dtm, points_test))
  
    File "C:\Users\k\Anaconda3\lib\site-packages\scipy\sparse\construct.py", line 464, in hstack
      return bmat([blocks], format=format, dtype=dtype)
  
    File "C:\Users\k\Anaconda3\lib\site-packages\scipy\sparse\construct.py", line 581, in bmat
      'row dimensions' % i)
  
  ValueError: blocks[0,:] has incompatible row dimensions
  </code></pre>