title: find index of the start of a range of rows matching a specific range in pandas dataframe
body: <p>python noob here trying to delete sets of rows in a dataset that meets certain criteria. The sets of rows are in chunks over a given timestamp range, but can occur any number of times over the full timeline of valid data.</p>
  <p>To track where the event of interest occurs, I've created an extra column &quot;Moved&quot; to indicate rows of interest based on a formula applied to column Value and used the assignment operator for pd.loc[(criteria), 'Moved'] = 1,0,-1;</p>
  <p>where</p>
  <p>Moved = 1 (nominal data and can be within bad data sets. I want to count these that aren't within the bad range),</p>
  <p>Moved = 0 (nominal data),</p>
  <p>Moved = -1 (bad data has at a minimum started from now, but at max 100 rows prior, and for the next few days (data period is 4s)).</p>
  <p>I created a loop that drops a chunk of the dataframe starting from the next occurrence of Moved = -1 index until the sum of the next 100 &quot;Moved&quot; values=0, I stop dropping indexes. Then I search again for a -1 index start. This takes a long time and then once the out-of-range values run out, I get an indexing error. The algorithm would restart the loop and drop the next chunk of data if it finds the Moved = -1.</p>
  <p>The pseudo-code that I've implemented is like:</p>
  <pre class="lang-py prettyprint-override"><code>while pd.Moved.loc[pd.Moved == -1].count() &gt; 0:
     good_index = ** find the next index where 100 consecutive &quot;Moved&quot; rows == 0 **
     pd.drop(pd[(pd.index &gt;= pd.Moved.loc[pd.Moved == -1].index[0])][:rows_to_delete].index, inplace=True
  </code></pre>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>index</th>
  <th>Value</th>
  <th>Moved</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>time x</td>
  <td>remove -100 rows up to be sure</td>
  <td>0</td>
  </tr>
  <tr>
  <td>time1</td>
  <td>bad data starts</td>
  <td>-1</td>
  </tr>
  <tr>
  <td>time x</td>
  <td>xxx</td>
  <td>0</td>
  </tr>
  <tr>
  <td>time x</td>
  <td>xxx</td>
  <td>0</td>
  </tr>
  <tr>
  <td>time x</td>
  <td>xxx</td>
  <td>1</td>
  </tr>
  <tr>
  <td>time x</td>
  <td>xxx</td>
  <td>0</td>
  </tr>
  <tr>
  <td>time x</td>
  <td>xxx</td>
  <td>0</td>
  </tr>
  <tr>
  <td>time x</td>
  <td>xxx</td>
  <td>0 -&gt; 100 rows of 0 value indicates I want to stop dropping rows</td>
  </tr>
  <tr>
  <td>...</td>
  <td>good data</td>
  <td>&gt;-1</td>
  </tr>
  <tr>
  <td>time 2</td>
  <td>bad data starts again</td>
  <td>-1</td>
  </tr>
  <tr>
  <td>time y</td>
  <td>xxx</td>
  <td>1</td>
  </tr>
  <tr>
  <td>time y</td>
  <td>xxx</td>
  <td>0</td>
  </tr>
  <tr>
  <td>time y</td>
  <td>xxx</td>
  <td>0</td>
  </tr>
  <tr>
  <td>time x</td>
  <td>xxx</td>
  <td>0 -&gt; 100 rows of 0, bad data is done</td>
  </tr>
  <tr>
  <td>...</td>
  <td>good data</td>
  <td>&gt;-1</td>
  </tr>
  </tbody>
  </table>
  </div>