Subtracting multiple columns and appending results in pandas DataFrame
<p>I have a table of sensor data, for which some columns are measurements and some columns are sensor bias.  For example, something like this:</p>

<pre><code>df=pd.DataFrame({'x':[1.0,2.0,3.0],'y':[4.0,5.0,6.0],
                 'dx':[0.25,0.25,0.25],'dy':[0.5,0.5,0.5]})
</code></pre>

<blockquote>
<pre><code>    dx   dy    x    y
0  0.25  0.5  1.0  4.0
1  0.25  0.5  2.0  5.0
2  0.25  0.5  3.0  6.0
</code></pre>
</blockquote>

<p>I can add a column to the table by subtracting the bias from the measurement like this:</p>

<pre><code>df['newX'] = df['x'] - df['dx']
</code></pre>

<blockquote>
<pre><code>    dx   dy    x    y  newX
0  0.25  0.5  1.0  4.0  0.75
1  0.25  0.5  2.0  5.0  1.75
2  0.25  0.5  3.0  6.0  2.75
</code></pre>
</blockquote>

<p>But I'd like to do that for many columns at once.  This doesn't work:</p>

<pre><code>df[['newX','newY']] = df[['x','y']] - df[['dx','dy']]
</code></pre>

<p>for two reasons, it seems.</p>

<ul>
<li>When subtracting DataFrames the column labels are used to align the subtraction, so I wind up with a 4 column result <code>['x', 'y', 'dx', 'dy']</code>.</li>
<li>It seems I can insert a single column into the DataFrame using indexing, but not more than one.</li>
</ul>

<p>Obviously I can iterate over the columns and do each one individually, but is there a more compact way to accomplish what I'm trying to do that is more analogous to the one column solution?  </p>