title: How to multiply every column of one Pandas Dataframe with every column of another Dataframe efficiently?
body: <p>I'm trying to multiply two pandas dataframes with each other. Specifically, I want to multiply every column with every column of the other df. </p>
  
  <p>The dataframes are one-hot encoded, so they look like this: </p>
  
  <pre><code>col_1, col_2, col_3, ...
   0      1      0 
   1      0      0 
   0      0      1 
   ...
  </code></pre>
  
  <p>I could just iterate through each of the columns using a for loop, but in python that is computationally expensive, and I'm hoping there's an easier way. </p>
  
  <p>One of the dataframes has 500 columns, the other has 100 columns. </p>
  
  <p>This is the fastest version that I've been able to write so far: </p>
  
  <pre><code>interact_pd = pd.DataFrame(index=df_1.index)
  df1_columns = [column for column in df_1]
  for column in df_2:
      col_pd = df_1[df1_columns].multiply(df_2[column], axis="index")
      interact_pd = interact_pd.join(col_pd, lsuffix='_' + column)
  </code></pre>
  
  <p>I iterate over each column in df_2 and multiply all of df_1 by that column, then I append the result to interact_pd. I would rather not do it using a for loop however, as this is very computationally costly. Is there a faster way of doing it?</p>
  
  <p>EDIT: example </p>
  
  <p>df_1: </p>
  
  <pre><code>1col_1, 1col_2, 1col_3
   0      1      0 
   1      0      0 
   0      0      1 
  </code></pre>
  
  <p>df_2: </p>
  
  <pre><code>2col_1, 2col_2
   0      1       
   1      0       
   0      0      
  </code></pre>
  
  <p>interact_pd:</p>
  
  <pre><code>1col_1_2col_1, 1col_2_2col_1,1col_3_2col_1, 1col_1_2col_2, 1col_2_2col_2,1col_3_2col_2
  
    0      0      0        0       1        0  
    1      0      0        0       0        0 
    0      0      0        0       0        0 
  </code></pre>