Search code examples
pythondrop

delete rows in a dataframe untill it finds a certain value with python


So I need this little piece of code to keep dropping rows until the A1 cell is a specific string, I tried this:

while table[0][0] != 'Nº TAD':
    table = table.drop(table.index[0])

but it seems the loop keeps going for more than I want and I have no idea why


Solution

  • You can itereate over rows like this:

    for index, row in table.iterrows():
       if row["col_name"] == 'Nº TAD':
            break
       table.drop([index],inplace=True)