SyntaxFix
Write A Post
Hire A Developer
Questions
You can do it in one line -
df.groupby(['job']).apply(lambda x: x.sort_values(['count'], ascending=False).head(3) .drop('job', axis=1))
what apply() does is that it takes each group of groupby and assigns it to the x in lambda function.