I have the following code:
indices_to_remove= []
for i in range(0,len(df)):
if (df.speed.values[i] <= 15 ):
counter += 1
if counter > 600:
indices_to_remove.append(i)
else:
counter= 0
df= df.drop (indices_to_remove, axis=0)
The main goal of this code is to loop through all the rows in my dataset, and in case there are more than 600 consecutive rows that has a speed value less than 15. The code will add the rows indices to the indices_to_remove and then all of these rows will be dropped. My main issue in this code is that: let's consider a case scenario where we have 1000 consecutive rows. The code will only append the rows indices starting from 601 till 1000 and won't ignore the rows from zero to 600. Can someone help me to modify this code so that it includes all the rows starting from zero till the last column that has a speed value less than 15.
Aucun commentaire:
Enregistrer un commentaire