我正在寻找一个有效的函数来查找至少连续出现三次且没有中断的标记.
输入示例:
import pandas as pd
marks = [83, 79, 83, 83, 83, 79, 79, 83]
student_id = [101, 102, 103, 104, 105, 106, 107, 108]
d = {'student_id':student_id,'marks':marks}
df = pd.DataFrame (d)
期望输出:
83
如果可能的话,我正在寻找一种比用for
个循环逐行循环更有效的方法来跟踪前两个标记.也就是说,我在寻找比以下更好的东西:
def thrice_f (marks, number_of_apperances):
cache = marks[0]
counter = 1
for mark in marks[1:]:
if mark == cache:
counter += 1
if counter == number_of_apperances:
return cache
else:
counter = 1
cache = mark