title: use Featureunion in scikit-learn to combine two pandas columns for tfidf
body: <p>While using <a href="http://zacstewart.com/2015/04/28/document-classification-with-scikit-learn.html" rel="noreferrer">this</a> as a model for spam classification, I'd like to add an additional feature of the Subject plus the body.</p>
  
  <p>I have all of my features in a pandas dataframe. For example, the subject is df['Subject'], the body is df['body_text'] and the spam/ham label is df['ham/spam'] </p>
  
  <p>I receive the following error:
  TypeError: 'FeatureUnion' object is not iterable</p>
  
  <p>How can I use both df['Subject'] and df['body_text'] as features all while running them through the pipeline function? </p>
  
  <pre><code>from sklearn.pipeline import FeatureUnion
  features = df[['Subject', 'body_text']].values
  combined_2 = FeatureUnion(list(features))
  
  pipeline = Pipeline([
  ('count_vectorizer',  CountVectorizer(ngram_range=(1, 2))),
  ('tfidf_transformer',  TfidfTransformer()),
  ('classifier',  MultinomialNB())])
  
  pipeline.fit(combined_2, df['ham/spam'])
  
  k_fold = KFold(n=len(df), n_folds=6)
  scores = []
  confusion = numpy.array([[0, 0], [0, 0]])
  for train_indices, test_indices in k_fold:
      train_text = combined_2.iloc[train_indices]
      train_y = df.iloc[test_indices]['ham/spam'].values
  
      test_text = combined_2.iloc[test_indices]
      test_y = df.iloc[test_indices]['ham/spam'].values
  
      pipeline.fit(train_text, train_y)
      predictions = pipeline.predict(test_text)
      prediction_prob = pipeline.predict_proba(test_text)
  
      confusion += confusion_matrix(test_y, predictions)
      score = f1_score(test_y, predictions, pos_label='spam')
      scores.append(score)
  </code></pre>