remove rows from a table but make the index of the rows according to the number of items

Viewed 59

I made a script for a table, but sometimes the table maker inserts some things that aren't values. I wanted to do something automatic, without having to go into the tables and remove those rows. I managed to remove these lines, but the index of the lines remains and I need the index of the lines to be correct (0, 1, 2, 3, 4, 5, 6...)

For example, in the table I'm currently using, the row with index 0 has to be removed and when I make the new table the table's index starts with 1

for i in range(table.shape[0]):
    if pd.isna(table[1][i]) == True:
        table = table.drop(labels=i, axis=0)
 
table2 = pd.DataFrame(table)
2 Answers

You can reset the index

table2 = table2.reset_index(drop=True)

With Keith Johnson's answer, I researched and managed to find the solution

table2.reset_index(inplace=True, drop=True)
Related