Home > Back-end >  Repetition of the same results consecutif
Repetition of the same results consecutif

Time:03-25

I need to check if I have repetition 4 times the same value for "PCR POS/Neg" consecutive, 3 times in my "output_df".

How i can do it ?

def results1(file1,file2):

    results_list = defaultdict(list)
    names_loc = file2
    listing_file = pd.read_excel(file1, index_col=None)
    headers = ['Vector Name', 'Date and Time', 'Test ID', 'PCR POS/Neg']
    output_df = pd.DataFrame(columns=headers)

    with open(names_loc, "r") as fp:
        for line in fp.readlines():
            line = line.rstrip("\\\n")
            full_name = line.split(',')
            sample_name = full_name[0].split('_mean')
          
    output_df['Date and Time'] = pd.to_datetime(output_df['Date and Time'])

CodePudding user response:

df = pd.DataFrame({'value' : ['A','A','A','A', 'B','B','C','C','C','B','B']})

df['new'] = df["value"].apply(lambda x: ord(x))
np.floor(df["new"].diff().eq(0).sum()/3)
  • Related