title: Cartesian product of a pandas dataframe with itself
body: <p>Given a dataframe:</p>
  
  <pre><code>    id  value
  0    1     a
  1    2     b
  2    3     c
  </code></pre>
  
  <p>I want to get a new dataframe that is basically the cartesian product of each row with each other row <em>excluding itself</em>:</p>
  
  <pre><code>    id  value id_2 value_2
  0    1     a     2    b
  1    1     a     3    c
  2    2     b     1    a
  3    2     b     3    c
  4    3     c     1    a
  5    3     c     2    b
  </code></pre>
  
  <p>This is my approach as of now. I use itertools to get the product and then use <code>pd.concat</code> with <code>df.loc</code> to get the new dataframe.</p>
  
  <pre><code>from itertools import product
  
  ids = df.index.values
  ids_1, ids_2 = list(zip(*filter(lambda x: x[0] != x[1], product(ids, ids))))
  
  df_new = pd.concat([df.loc[ids_1, :].reset_index(), df.loc[ids_2, :].reset_index()], 1).drop('index', 1)
  
  df_new
  
     id value  id value
  0   1     a   2     b
  1   1     a   3     c
  2   2     b   1     a
  3   2     b   3     c
  4   3     c   1     a
  5   3     c   2     b
  </code></pre>
  
  <p>Is there a simpler way?</p>