如何基于特定列值以增量因子循环数据框

我正在使用的数据框如下所示:

     vid2               FStart FEnd cap2                                               VDuration  COS  cap1
0    -_aaMGK6GGw_57_61  0      3    A man grabbed a boy from his collar and threw ...  4          2    A man and woman are yelling at a young boy and...  0.253792   0.750000
1    -_aaMGK6GGw_57_61  3      4    A lady is waking up a man lying on a chair and...  4          2    A man and woman are yelling at a young boy and...  0.192565   0.250000
2    -_hbPLsZvvo_5_8    0      1    A white dog is barking and a caption is writte...  3          2    a dog barking and cooking with her master in t...  0.562707   0.333333
  ...                ...    ...  ...                                                ...        ...  ...
379  6Lzq1HN33lE_5_15   0      10   A man is playing flute.                            10         1    A man is playing the title song of 'The Titani...  0.363582   1.000000
380  6mYnZbIwcNo_10_16  0      6    A man is typing using an external keyboard att...  6          1    One types on ...                                   0.365895   1.000000
381  6njscWrdnM0_8_18   0      5    A man practicing kicks on a toy torso dummy fa...  10         2    A time a man karate kicks a mannequin he fa...     0.187248   0.500000
382  6njscWrdnM0_8_18   5      10   The man is punching the dummy.                     10         2   Each time a man karate kicks a mannequin he fa...   0.234586   0.500000

我正在尝试为此处为vid2的每个视频ID计算加权相似度得分。但是,每个视频分别有许多字幕和权重。它有所不同,有的有2个,有的1个,有的3个,依此类推。此数量的段和标题已存储在功能部件COS中(即段数)。

我想遍历每个视频的分数存储为fsim的加权平均分数(片段相似度分数)的数据帧。但是迭代次数不是规则的。

我已经尝试过此代码。但是我无法以迭代因子为COS而不是仅恒定值进行动态迭代

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)