title: How to collectively set the values of multiple columns for certain selected rows for Pandas dataframe?
body: <p>I have a dataframe <code>df</code> which has <code>'TPrice','THigh','TLow','TOpen','TClose','TPCLOSE'</code> columns, and now I want to set <code>'TPrice','THigh','TLow','TOpen','TClose'</code> columns values to be same as <code>'TPCLOSE'</code> column for the rows whose <code>TPrice</code> column value is zero.</p>
  
  <p>Show some rows whose TPrice is 0:</p>
  
  <pre><code>&gt;&gt;&gt; df[df['TPrice']==0][['TPrice','THigh','TLow','TOpen','TClose','TPCLOSE']][0:5]
      TPrice  THigh  TLow  TOpen  TClose  TPCLOSE
  13       0      0     0      0       0     4.19
  19       0      0     0      0       0     7.74
  32       0      0     0      0       0     3.27
  43       0      0     0      0       0    12.98
  60       0      0     0      0       0     7.48
  </code></pre>
  
  <p>Then assignment :</p>
  
  <pre><code>&gt;&gt;&gt; df[df['TPrice']==0][['TPrice','THigh','TLow','TOpen','TClose']] = df['TPCLOSE']
  </code></pre>
  
  <p>But Pandas doesn't really change df , for below code still can find some rows:</p>
  
  <pre><code>&gt;&gt;&gt; df[df['TPrice']==0][['TPrice','THigh','TLow','TOpen','TClose','TPCLOSE']][0:5]
      TPrice  THigh  TLow  TOpen  TClose  TPCLOSE
  13       0      0     0      0       0     4.19
  19       0      0     0      0       0     7.74
  32       0      0     0      0       0     3.27
  43       0      0     0      0       0    12.98
  60       0      0     0      0       0     7.48
  </code></pre>
  
  <p>So how to do ?</p>
  
  <p><strong>Update for Jeff solution:</strong></p>
  
  <pre><code>&gt;&gt;&gt; quote_df = get_quote()
  &gt;&gt;&gt; quote_df[quote_df['TPrice']==0][['TPrice','THigh','TLow','TOpen','TClose','TPCLOSE','RT','TVol']][0:5]
      TPrice  THigh  TLow  TOpen  TClose  TPCLOSE   RT  TVol
  13       0      0     0      0       0     4.19 -100     0
  32       0      0     0      0       0     3.27 -100     0
  43       0      0     0      0       0    12.98 -100     0
  45       0      0     0      0       0    26.74 -100     0
  60       0      0     0      0       0     7.48 -100     0
  &gt;&gt;&gt; row_selection = quote_df['TPrice']==0
  &gt;&gt;&gt; col_selection = ['THigh','TLow','TOpen','TClose']
  &gt;&gt;&gt; for col in col_selection:
  ...     quote_df.loc[row_selection, col] = quote_df['TPCLOSE']
  ... 
  &gt;&gt;&gt; quote_df[quote_df['TPrice']==0][['TPrice','THigh','TLow','TOpen','TClose','TPCLOSE','RT','TVol']][0:5]
      TPrice  THigh  TLow  TOpen  TClose  TPCLOSE   RT  TVol
  13       0   4.19  4.19   4.19    4.19     4.19 -100     0
  32       0   4.19  4.19   4.19    4.19     3.27 -100     0
  43       0   4.19  4.19   4.19    4.19    12.98 -100     0
  45       0   4.19  4.19   4.19    4.19    26.74 -100     0
  60       0   4.19  4.19   4.19    4.19     7.48 -100     0
  &gt;&gt;&gt; 
  </code></pre>