title: Splitting DataFrame into groups - how to use a windowing function on a DataFrame
body: <p>I want to group non-zero values together, where a group is defined as a sublist of sequential element(s) that contain all non-zero values, segregated by surrounding 0-valued element(s). For example:</p>
  
  <pre><code>values = [0, 0, 0, 1, 2, 3, 0, 0, 3, 3, 4, 3, 0, 0, 5]
  ... # do some splitting, grouping, black magic, etc.
  values = [[1, 2, 3], [3, 3, 4, 3], [5]]
  </code></pre>
  
  <p>This concept kinda sounds like using a windowing function in PostgreSQL. I'm trying to figure out an efficient/elegant way of doing the same sort of thing with a DataFrame.</p>
  
  <p>I'm working with temporal data, so the resulting groups also need to maintain their original order. For instance, suppose I have the following DataFrame:</p>
  
  <pre><code> timestamp value
  2018-01-01     0
  2018-01-02     0
  2018-01-03     1
  2018-01-04     2
  2018-01-05     3
  2018-01-06     0
  2018-01-07     0
  2018-01-08     3
  2018-01-09     0
  2018-01-11     5
  2018-01-12     5
  2018-01-13     3
  2018-01-14     0
  2018-01-15     5
  </code></pre>
  
  <p>After splitting it into different groups, I would expect each group to be:</p>
  
  <pre><code># Group 1
  2018-01-03     1
  2018-01-04     2
  2018-01-05     3
  
  # Group 2
  2018-01-08     3
  
  # Group 3
  2018-01-11     5
  2018-01-12     5
  2018-01-13     3
  
  # Group 4
  2018-01-15     5
  </code></pre>
  
  <p>I've seen similar problems that use an assortment of methods on a DataFrame (<code>groupby()</code>, <code>cumsum()</code>, <code>rolling()</code>, etc.), but nothing that fits my exact needs. I found <a href="https://pandas.pydata.org/pandas-docs/stable/groupby.html" rel="nofollow noreferrer">this bit of documentation</a> 
  that seems to address this type of problem, but came out empty handed. Help, anyone?</p>