pandas DataFrame: How to cut a dataframe using custom ways?
<p>I want to cut a DataFrame to several dataframes using my own rules.</p>

<pre><code>&gt;&gt;&gt; data = pd.DataFrame({'distance':[1,2,3,4,5,6,7,8,9,10],'values':np.arange(0,1,0.1)})
&gt;&gt;&gt; data
   distance  values
0         1     0.0
1         2     0.1
2         3     0.2
3         4     0.3
4         5     0.4
5         6     0.5
6         7     0.6
7         8     0.7
8         9     0.8
9        10     0.9
</code></pre>

<p>I'll cut <code>data</code> according to values of <code>distance</code> column. For example, there's some bins <code>[1,3),[3,8),[8,10),[10,10+)</code>, if data's column <code>distance</code> in same bin,I separate them into same group and compute column <code>values</code> average value or sum value.That is</p>

<pre><code>&gt;&gt;&gt; data1 = data[lambda df:(df.distance &gt;= 1) &amp; (df.distance &lt; 3)]
&gt;&gt;&gt; data1
   distance  values
0         1     0.0
1         2     0.1
&gt;&gt;&gt; np.mean(data1['values'])
0.05
</code></pre>

<p>How can I cut origin DataFrame into several groups(and then save them,process them...) efficiently?</p>