Adding pandas columns to a sparse matrix : <p>I have additional derived values for X variables that I want to use in my model. </p>

<pre><code>XAll = pd_data[['title','wordcount','sumscores','length']]
y = pd_data['sentiment']
X_train, X_test, y_train, y_test = train_test_split(XAll, y, random_state=1)
</code></pre>

<p>As I am working with text data in title, I first convert it to a dtm separately:</p>

<pre><code>vect = CountVectorizer(max_df=0.5)
vect.fit(X_train['title'])
X_train_dtm = vect.transform(X_train['title'])
column_index = X_train_dtm.indices

print(type(X_train_dtm))    # This is &lt;class 'scipy.sparse.csr.csr_matrix'&gt;
print("X_train_dtm shape",X_train_dtm.get_shape())  # This is (856, 2016)
print("column index:",column_index)     # This is column index: [ 533  754  859 ...,  633  950 1339]
</code></pre>

<p>Now that I have the text as a document term matrix, I would like to add the other features like 'wordcount','sumscores','length' to X_train_dtm which are numeric. This I shall create the model using the new dtm and thus would be more accurate as I would have inserted additinal features.</p>

<p>How do I add additional numeric columns of the pandas dataframe to a sparse csr matrix?</p>
