How can I extract data using the 'groupby'
<pre><code>import pandas as pd

df= pd.DataFrame({'date':[1,2,3,4,5,1,2,3,4,5,1,2,3,4,5],
     'name':list('aaaaabbbbbccccc'),
     'v1':[10,20,30,40,50,10,20,30,40,50,10,20,30,40,50],
     'v2':[10,20,30,40,50,10,20,30,40,50,10,20,30,40,50],
     'v3':[10,20,30,40,50,10,20,30,40,50,10,20,30,40,50]})

a= list(set(list(df.name)))
plus=[]
for i in a:
    sep=df[df.name==i]
    sep2=sep[(sep.v1&gt;=10)&amp;(sep.v2&gt;=20)&amp;(sep.v3&lt;=40)]
    plus.append(sep2)
result=pd.concat(plus)
print(result)
</code></pre>

<p>I know this is not a good example anyway,</p>

<p>I would like to handle separately by name.</p>

<p>It takes too long in a big data</p>

<p>How can I extract  data using the 'groupby'?</p>

<p>Even better if the function is used(def..apply...)</p>

<p><code>df.groupby(['name'])(df['v1']&gt;20)</code>...???? It cannot work...</p>

<p>looking at your desired data set i don't think you need to <code>groupby</code> your <code>df</code>, you can simply filter it:</p>

<pre><code>In [112]: df.query('v1 &gt;= 10 and v2 &gt;= 20 and v3 &lt;= 40')
Out[112]:
    date name  v1  v2  v3
1      2    a  20  20  20
2      3    a  30  30  30
3      4    a  40  40  40
6      2    b  20  20  20
7      3    b  30  30  30
8      4    b  40  40  40
11     2    c  20  20  20
12     3    c  30  30  30
13     4    c  40  40  40
</code></pre>

python python-3.x pandas dataframe