title: how to loop a dataframe with increment factor based on a particular column value
body: <p>The dataframe I am working with looks like this:</p>
  
  <pre><code>                vid2  COS      fsim   FWeight
  0  -_aaMGK6GGw_57_61    2  0.253792  0.750000
  1  -_aaMGK6GGw_57_61    2  0.192565  0.250000
  2    -_hbPLsZvvo_5_8    2  0.562707  0.333333
  3    -_hbPLsZvvo_5_8    2  0.179969  0.666667
  4  -_hbPLsZvvo_18_25    1  0.275962  0.714286
  </code></pre>
  
  <p>Here, 
  the features have the following meanings:</p>
  
  <p><em>FWeight</em> - weight of each fragment (or row)</p>
  
  <p><em>fsim</em> - similarity score between the two columns <em>cap1</em> and <em>cap2</em></p>
  
  <p>The weighted formula is:
  <a href="https://i.stack.imgur.com/IpHwV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IpHwV.png" alt="Weighted formula"></a></p>
  
  <pre><code>For example, 
  For vid2 "-_aaMGK6GGw_57_61", COS = 2
  Thus, the two rows with vid2 comes under this.
  
     fsim       FWeight
  0  0.253792   0.750000
  1  0.192565   0.250000
  
  The calculated value vid_score needs to be 
  vid_score(1st video) = (fsim[0] * FWeight[0] + fsim[1] * FWeight[1])/(FWeight[0] + FWeight[1])
  
  The expected output value vid_score for vid2 = -_aaMGK6GGw_57_61 is 
  (0.750000) * (0.253792) + (0.250000) * (0.192565) 
  = 0.238485 (Final value)
  </code></pre>
  
  <p>For some videos, this COS = 1, 2, 3, 4, 5, ...
  Thus this needs to be dynamic</p>
  
  <p>I am trying to calculate the weighted similarity score for each video ID that is <em>vid2</em> here. However, there are a number of captions and weights respectively for each video. It varies, some have 2, some 1, some 3, etc. This number of segments and captions has been stored in the feature <em>COS</em> (that is, count of segments).</p>
  
  <p>I want to iterate through the dataframe where score for each video is stored as a weighted average score of the <em>fsim</em> (fragment similarity score). But the number of iteration is not regular. </p>
  
  <p>I have tried this code. But I am not able to iterate dynamically with the iteration factor being <em>COS</em> instead of just a constant value</p>
  
  <pre class="lang-py prettyprint-override"><code>vems_score = 0.0
  
  video_scores = []
  
  for i, row in merged.iterrows():
      vid_score = 0.0
      total_weight = 0.0
  
      for j in range(row['COS']):
          total_weight = total_weight + row['FWeight']
          vid_score = vid_score + (row['FWeight'] * row['fsim'])
  
      i = i + row['COS']
  
      vid_score = vid_score/total_weight
      video_scores.append(vid_score)
  
  print(video_scores)
  </code></pre>