title: Python For Loop executing unexpected number of loops
body: <p>I am using a nested for loop to read selective data from a dataframe.
  And then I need to implement some mathematical formulae to that selective data.
  For this reason, I implemented a dynamic logic that separated out the index and column numbers of the data in a list &quot;idx&quot; and &quot;cols&quot;.
  But the nested For Loop that I have applied to read this data is executing for unexpectedly greater number of times.</p>
  <p>Following is the sample code and its output:</p>
  <pre><code>idx =  [1, 2]
  cols = [2, 2]
  count = 0
  
  def run_imputation():
      global count
      for i in idx:
          for col in cols:
              count += 1
              print(count)
              dfClean.iloc[i, col] = tempOut[i,col]  #Need to do such and more computations
              origVal.append(dfClean_Orig.iloc[i, col])
              impuVal.append(dfClean.iloc[i, col])
  
  %timeit run_imputation()
  
  
  OUTPUT:
  1
  2
  ...... 
  32444
  </code></pre>
  <p>So my question is that why is For loop executing 32444 times, whereas it should just execute 4 times.
  And is there any better way for doing such selective data computations as shown below other than such complicated For Loops in Python?</p>