title: Transform slow pandas iterrows into apply
body: <p>I have the following dataframe:</p>
  
  <pre><code>   VALUE      COUNT  RECL_2007  RECL_2008  RECL_2009  A_A  A_B  A_C  B_A  B_B  \
  0    189   149.5872        503        503        500    0    0    0    0    0   
  1    209  1939.6160        503        503        503    0    0    0    0    0   
  2    499   617.4784        503        500        503    0    0    0    0    0   
  3    585    73.0688        503        503        503    0    0    0    0    0   
  4    611   133.9072        503        500        503    0    0    0    0    0   
  5    645   278.7904        503        503        503    0    0    0    0    0   
  6    659   138.2976        500        503        503    0    0    0    0    0   
  7    719   769.5744        503        503        502    0    0    0    0    0   
  
     B_C  C_A  C_B  C_C  
  0    0    0    0    0  
  1    0    0    0    0  
  2    0    0    0    0  
  3    0    0    0    0  
  4    0    0    0    0  
  5    0    0    0    0  
  6    0    0    0    0  
  7    0    0    0    0 
  </code></pre>
  
  <p>Also, the values in columns:RECL_2007, RECL_2008 and RECL_2009 correspond to the variables A, B and C as follows:</p>
  
  <pre><code> A = 500, B=502, C=503.
  </code></pre>
  
  <p>I want to fill the columns A_A...C_C using the values in the COUNT column such that the RECL_2007 value gives the first part of the column name and RECL_2009 gives the second part of the column name.</p>
  
  <p>I.e, if RECL_2007 == 503 and RECL_2009 == 500, then the column is C_A and its value should be updated to whatever is in the COUNT column of that row.</p>
  
  <p>Currently I am iterating through the pandas dataframe using iterrows:</p>
  
  <pre><code>for index, row in df.iterrows():    
     init = OPP_LU[row[name_init]] # Get first part of column name
     finl = OPP_LU[row[name_finl]] # Get second part of column name       
     col_name = init+'_'+finl
     df.loc[index,col_name] = row['COUNT']
  </code></pre>
  
  <p>This is slow, but I am not sure how to translate it into something using apply. Any hints?</p>