title: In Python (Pandas/Numpy), How to subset a df using a condition and a specific chunk size?
body: <p>I have a df</p>
  
  <pre><code>A = pd.DataFrame([[1, 5, 2, 0], [2, 4, 4, 0], [3, 3, 1, 1], [4, 2, 2, 0], [5, 1, 4, 0], [2, 4, 4, 0], [3, 3, 1, 1], [4, 2, 2, 0], [5, 1, 4, 0]],
                   columns=['A', 'B', 'C', 'D'], index=[1, 2, 3, 4, 5, 6, 7, 8, 9])
  </code></pre>
  
  <p>I want to be able to subset the dataframe according to the following rules: Select the rows which the column 'D' value is 1 and also include the two above them (Chunk Size = 3).</p>
  
  <p>If I apply the rule in the df example, the output should be:</p>
  
  <pre><code>   A  B  C  D
  1  1  5  2  0
  2  2  4  4  0
  3  3  3  1  1
  5  5  1  4  0
  6  2  4  4  0
  7  3  3  1  1
  </code></pre>
  
  <p>Thanks</p>