Pandas operations on selected columns
<p>I want to standardize certain columns in my pandas dataframe.</p>

<pre><code>dfTest = pd.DataFrame({
           'A':[14.00,90.20,90.95,96.27,91.21],
           'B':[103.02,107.26,110.35,114.23,114.68], 
           'C':['big','small','big','small','small']
         }) 
</code></pre>

<p>This does not work as only a single index can be set. In case only a single column like 'A' is selected sklearn emits several deprecation warnings</p>

<pre><code>scaler = StandardScaler()
dfTest['A_scaled', 'B_scaled'] = scaler.fit_transform(dfTest[['A', 'B']])
dfTest
</code></pre>

<p>How could I achieve something like that? </p>

<p>You could concatenate the scaled columns to the original <code>DF</code> as shown:</p>

<pre><code>scaler = StandardScaler()
scaled_data = pd.DataFrame(data=scaler.fit_transform(dfTest[['A', 'B']]), 
                           columns=['A_scaled', 'B_scaled'])

pd.concat([dfTest, scaled_data], axis=1)
</code></pre>

<p><a href="http://i.stack.imgur.com/LulfV.png" rel="nofollow"><img src="http://i.stack.imgur.com/LulfV.png" alt="Image"></a></p>

python pandas scikit-learn