score_sum = 0
last_score = [0] * (np.max(page_id) + 1)
result = np.empty_like(scores)
for i, (pid, score) in enumerate(zip(page_id, scores)):
    score_sum = score_sum - last_score[pid] + score
last_score[pid] = score
result[i] = score_sum
result.name = 'score_sum'
return result
print(score_sum_py(pd.factorize(df.page_id)[0], df.score))
How to accumulate unique sum of columns across pandas index