What is the equivalent of SQL “GROUP BY HAVING” on Pandas?

前端 未结 2 476
粉色の甜心
粉色の甜心 2020-12-05 01:53

what would be the most efficient way to use groupby and in parallel apply a filter in pandas?

Basically I am asking for the equivalent in SQL of

sele         


        
2条回答
  •  -上瘾入骨i
    2020-12-05 02:18

    I group by state and county where max is greater than 20 then subquery the resulting values for True using the dataframe loc

    counties=df.groupby(['state','county'])['field1'].max()>20
    counties=counties.loc[counties.values==True]
    

提交回复
热议问题