python pandas get index boundaries from a series of Booleans
<p>I am trying cut videos based on some caracteristics.
My current strategy leads on a <code>pandas</code> series of booleans for each frame, indexed by timestamp. <code>True</code> to keep it, <code>False</code> to dump it.</p>

<p>As I plan to cut videos, i need to extract boundaries from this list, so that i can tell fmpeg beginning and end of the parts I want to extract from the main video.</p>

<p>Tu sum up :</p>

<p>I have a <code>pandas</code> Series which looks like this:</p>

<pre><code>acquisitionTs
0.577331     False
0.611298     False
0.645255     False
0.679218     False
0.716538     False
0.784453      True
0.784453      True
0.818417      True
0.852379      True
0.886336      True
0.920301      True
0.954259     False
             ...  
83.393376    False
83.427345    False
dtype: bool
</code></pre>

<p>(truncated for presenting reasons, but the TimeStamp usually begins at 0)</p>

<p>and I need to get boundaries of <code>True</code> sequences, so in this example i should get <code>[[t_0,t_1],[t_2,t_3]n, ... [t_2n-1,t_2n]]</code> , with <code>t_0 = 0.784453</code> and <code>t_1 = 0.920301</code> if I have <code>n</code> different sequences of <code>True</code> in my pandas Series.</p>

<p>Now that probleme seems very simple, in fact you can just shift the sequence by one and a make a xor between the to get a list of boolean with <code>True</code> being for boundaries</p>

<pre><code>e = df.shift(periods=1, freq=None, axis=0)^df
print(e[e].index)
</code></pre>

<p>(with <code>df</code> being a pandas Series)
there is still some work to do, like figuring if first element is a rising edge or a falling edge, but this hack works.</p>

<p>However that doesn't seem very pythonic. In fact, the probleme is so simple I believe that there must be somewhere in <code>pandas</code>, <code>numpy</code> or even <code>python</code> a prebuilt function for this which would fit nicely in a single function call instead of a hack like above. The <code>groupby</code> function seems promising though, but i never used it before.</p>

<p>How would be the best way of doing this ?</p>