title: Trouble with pandas iterrows and loop counter
body: <p>I have a dataset containing the US treasury curve for each day over a few years. Rows = Dates, Columns = tenor of specific treasury bond (3 mo, 1 yr, 10yr, etc) </p>
  
  <p>I have python code that loops through each day and calibrates parameters for an interest rate model. I am having trouble looping through each row via iterrows and with my loop counter. The goal is to go row by row and calibrate the model to that daily curve, store the calibrated parameters in a dataframe, and then move onto the next row and repeat.</p>
  
  <pre><code>def do_calibration_model1():
      global i
      for index, row in curves.iterrows():      
          day = np.array(row) #the subsequent error_fxn uses this daily curve
          calibration()
      i += 1
  
  def calibration():
      i = 0
      param = scipy.brute(error_fxn, bounds...., etc.)
      opt = scipy.fmin(error_fxn, param, xtol..., ftol...)
      calibration.loc[i] = np.array(opt) # store result of minimization (parameters for that day)
  </code></pre>
  
  <p>The code works correctly for the first iteration but then keeps repeating the calibration for the first row in the dataframe (curves). Further, it does not store the parameters in the next row of the calibration dataframe. I view the first issue as relating to the iterrows while the second is an issue of the loop counter. </p>
  
  <p>Any thoughts on what is going wrong? I have a Matlab background and find the pandas setup to be very frustrating.</p>
  
  <p>For reference I have consulted the links below to no avail.</p>
  
  <p><a href="https://www.python.org/dev/peps/pep-0212/" rel="nofollow">https://www.python.org/dev/peps/pep-0212/</a></p>
  
  <p><a href="http://nipunbatra.github.io/2015/06/pandas-iteration/" rel="nofollow">http://nipunbatra.github.io/2015/06/pandas-iteration/</a></p>
  
  <p>Per Jason's comment below I have updated the code to:</p>
  
  <pre><code>def do_calibration_model1():
      global i
      for index, row in curves.iterrows():
          for i in range(0,len(curves)):      
              day = np.array(row) #the subsequent error_fxn uses this daily curve
              param = scipy.brute(error_fxn, bounds...., etc.)
              opt = scipy.fmin(error_fxn, param, xtol..., ftol...)
              calibration.loc[i] = np.array(opt) # store result of minimization  (parameters for that day)
              i += 1
  </code></pre>
  
  <p>The revised code now places the appropriate parameters in each row of the calibration dataframe based on the loop counter. </p>
  
  <p>*However, it still does not move to the second (or subsequent rows) of the curves dataframe for the pandas iterrows function.</p>