dimanche 28 avril 2019

How to drop rows that: 1) don't meet a certain criteria and 2) the number of consecutive rows are great?

I am trying to set a certain condition and count the consecutive rows that meet this condition and if the count >100. I don't want to drop all of the rows but to keep the first 10 and last 10 rows and delete everything in between (in this case 80 rows). On the other hand, if the count < 100 no rows will be dropped

count = 0

for i in range (len(df.speed)):
   if (df.speed.values [i] <= 15 ):
       count += 1


       if count > 100: 


I am mainly stuck in how to delete the rows that are in the middle and to keep the first and last 10 rows. Would appreciate if someone can give a hint. Thanks

Aucun commentaire:

Enregistrer un commentaire