title: Using `itertools` to combine DataFrame columns
body: <p>I have a <code>DataFrame</code> which looks like this toy example:</p>
  <pre><code>import pandas as pd
  df = np.array([
      [20.078,19.679,19.585,19.406,19.37,14.97,13.992,20.122,20.736],
      [20.443,19.115,18.918,18.749,18.698,14.638,14.041,21.646,21.456],
      [19.723,19.593,19.353,19.175,19.258,15.193,14.354,21.122,21.09],
      [19.683,19.393,19.273,18.995,18.95,15.545,14.53,22.465,20.091],
      [19.769,19.233,19.083,18.983,18.768,14.978,14.224,21.684,20.314],
      [19.908,19.5,19.065,18.838,18.354,13.837,13.016,21.307,21.234]
  ])
  
  df = pd.DataFrame(df, columns = ['u', 'g', 'r', 'i', 'zmag', 'W1', 'W2', 'NUV', 'FUV'])
  </code></pre>
  <p>and I want to combine the columns pairwise into subtractive combinations, which is what this snippet does:</p>
  <pre><code>df['FUV_NUV'] = dataset['FUV'] - dataset['NUV']
  df['FUV_u'] = df['FUV'] - df['u']
  df['u_g'] = df['u'] - df['g']
  df['g_r'] = df['g'] - df['r']
  df['r_i'] = df['r'] - df['i']
  df['i_z'] = df['i'] - df['zmag']
  df['z_W1'] = df['zmag'] - df['W1']
  df['W1_W2'] = df['W1'] - df['W2']
  </code></pre>
  <p>But of course, there's a nicer way to do this, which I found <a href="https://www.titanwolf.org/Network/q/685e646b-8e72-426e-a3f1-f54330310302/y" rel="nofollow noreferrer">here</a>:</p>
  <pre><code>combs = list(chain.from_iterable(combinations(df.columns, i)
                                   for i in range(2, len(df.columns) + 1)))
  for cols in combs:
      df['_'.join(cols)] = df.loc[:, cols].sum(axis=1)
  </code></pre>
  <p>However, this produces <em>all</em> combinations (such as <code>u+g+W1+W2+...</code>) additively.</p>
  <p>How can I change it so that it</p>
  <ol>
  <li>iterates through the columns to produce all combinations of two columns maximum (eg: u-g, u-r, u-i, u-zmag, ...)</li>
  <li>subtractive (i.e. not <code>sum</code>)?</li>
  </ol>