jeudi 20 août 2020

Nested else loop within a while loop in python

I am trying to get data from a table and creating a dataframe using pandas. Using that dataframe, I need to run this logic where if the value of the column is not Yes, it needs to keep looping but when the value of the column is Yes nnd the number is less than or equal to value of column 2, it needs to stop for that cycle. If not, it needs to complete running until value of column 3 is not yes and number is less than or equal to value of column 2

cursor.execute(select * from material)
mat_df = as_pandas(cursor)
mat_df_header = list(mat_df.columns.values)

num = 2
for index, row in mat_df.iterrows():
        while row[mat_df_header[3]] != "Yes":
                if row[mat_df_header[3]] == "Yes" and num <= row[mat_df_header[2]]:
                    break
                if row[mat_df_header[3]] != "Yes" and num <= row[mat_df_header[2]]:
                    # do something
              num += 1

Aucun commentaire:

Enregistrer un commentaire