min() operation on nested groupby in pandas

梦想与她 提交于 2019-12-06 07:19:44

I think you need add columns to groupby - group by columns ANIMAL and AGE_Y:

df = df2.loc[df2.groupby(['ANIMAL','AGE_Y'])['AGE_D'].idxmin()]
df = df[['ANIMAL','AGE_Y','AGE_D']]
print (df)
   ANIMAL  AGE_Y  AGE_D
0       1      1      3
3       1      2    377
5       2      1      1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!