I am looking for an efficient function to find the marks which appear at least thrice one after another without interruption.
Input example:
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)
Desired output:
83
If it's possible, I am looking for something more efficient than looping row by row with a for loop that keeps track of the previous 2 marks. That is, I'm looking for something better than the following:
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