title: How to join output from sklearn preprocessing interaction variables back to original dataframe?
body: <p>I am trying to create interaction variables for a logistic regression model. I have 70+ features of which I only want to perform preprocessing on 6 of those features. Does anyone know how to take the numpy array from fit_transform and join these interactions back to may original dataframe? Also, is there an elegant way to label the interactions so I know what I am looking at? I’d imagine I’d take the numpy array and convert to dataframe via pd.DateFrame, but I am a little lost after that. Thank you in advance. I found the question below, but I was still somewhat confused for my particular use case.</p>
  
  <p><a href="https://stackoverflow.com/questions/35723472/how-to-use-sklearn-fit-transform-with-pandas-and-return-dataframe-instead-of-num">How to use sklearn fit_transform with pandas and return dataframe instead of numpy array?</a></p>
  
  <p>My code so far is as follows...</p>
  
  <pre><code># Subset of dataframe to create interaction variables from 
  df_interactions = df[['x1','x2','x3','x4','x5','x6']]
  
  from sklearn.preprocessing import PolynomialFeatures
  poly = PolynomialFeatures(interaction_only=True)
  df_interactions_T = poly.fit_transform(degrees=2, df_interactions)
  </code></pre>