Untitled

 avatar
unknown
plain_text
5 months ago
1.3 kB
2
Indexable
    def trace_back_parents_with_end_if(self,df, sequence_number):
        
        # print(indexes[0])
        print(type(df))
        print(df)
        result_rows = []
        end_if_rows = []

        current_seq = sequence_number
        print("\n\nPRITING SEQUENCE : \n\n")
        print(type(current_seq))
        print(current_seq)

        while True:
            row = df[df['Sequence'] == str(current_seq)]
            if row.empty:
                break

            result_rows.append(row)

            cond_seq = row['Conditional_Seq'].values[0]

            if pd.isna(cond_seq):
                break

            current_seq = str(int(float(cond_seq)))

        result_df = pd.concat(result_rows).sort_values(by='Sequence')

        for index, if_row in result_df.iterrows():
            if_seq = str(float(if_row['Sequence']))

            end_if_row = df[(df['Keywords'].str.startswith('END')) & 
                             (df['Conditional_Seq'] == if_seq)]

            if not end_if_row.empty:
                end_if_rows.append(end_if_row)

        if end_if_rows:
            end_if_df = pd.concat(end_if_rows)
            final_df = pd.concat([result_df, end_if_df]).sort_values(by='Sequence')
        else:
            final_df = result_df
        print("PRINTING TRACE BACKC DF:",final_df)
        return final_df
Editor is loading...
Leave a Comment