I'm trying to list the movies with the most number of ranking for each occupation. This is what I did:
most_rated_occ =lens.groupby(['occupation','title']).size().sort_values(ascending=False).to_frame()
And the result looks like this:
But now, I want each group to be shown up to 10 movies each. Top 10 items for student, top 4 items for lawyer(because there are less then 10 movies in the lawyer group) and so on. Any ideas on how to approach?
- I have tried Pandas get topmost n records within each group like this :
most_rated_occ =lens.groupby(['occupation','title']).head(10).size().sort_values(ascending=False).to_frame()
But it says TypeError: 'numpy.int32' object is not callable.