Panda how to groupby rows into different time buckets?
<p>I have a dataframe with a datetime type column called timestamp, I want to split the dataframe into several dataframes based on timestamp the time part, each dataframe contains rows that value by its value modulo x minutes, where x is a variable. </p>

<p>Notice that <code>e</code> and <code>f</code> are not in original order.  With modulo 10 minutes, I want all times that end in <code>3</code> together, all times that end in <code>1</code> together, so on and so forth.</p>

<p>Group when x = 10</p>

<pre><code>       timestampe            text
0  2016-08-11 12:01:00        a
1  2016-08-13 11:11:00        b
2  2016-08-09 11:13:00        c
3  2016-08-05 11:33:00        d
4  2016-08-19 11:27:00        e
5  2016-08-21 11:43:00        f
</code></pre>

<p>into </p>

<pre><code>       timestampe            text
0  2016-08-11 12:01:00        a
1  2016-08-13 11:11:00        b

0  2016-08-09 11:13:00        c
1  2016-08-05 11:33:00        d
2  2016-08-21 11:43:00        f

0  2016-08-19 11:27:00        e
</code></pre>

<p>Your main tools will be <code>df.timestampe.dt.minute % 10</code> and <code>groupby</code>.<br>
I used an <code>apply(pd.DataFrame.reset_index)</code> just as a convenience to illustrate</p>

<pre><code>df.groupby(df.timestampe.dt.minute % 10).apply(pd.DataFrame.reset_index)
</code></pre>

<p><a href="http://i.stack.imgur.com/3saqd.png" rel="nofollow"><img src="http://i.stack.imgur.com/3saqd.png" alt="enter image description here"></a></p>

<hr>

<p>Just using the <code>groupby</code> could be advantageous as well</p>

<pre><code>for name, group in df.groupby(df.timestampe.dt.minute % 10):
    print
    print(name)
    print(group)

1
           timestampe text
0 2016-08-11 12:01:00    a
1 2016-08-13 11:11:00    b

3
           timestampe text
2 2016-08-09 11:13:00    c
3 2016-08-05 11:33:00    d
5 2016-08-21 11:43:00    f

7
           timestampe text
4 2016-08-19 11:27:00    e
</code></pre>

python pandas numpy scipy