I know this is a frequently asked question, but I can't manage to make this run.
I have managed to group by a dataframe and find the count based on some other data. Now based on pandas, I want to find to return the top 5 cuisines per country based on the count.
My data is called df3:
country | cuisines | count |
---|---|---|
Australia | french | 12 |
Australia | italian | 19 |
Italy. | Italian | 3 |
France | Japanese | 5 |
France | Thailand | 9 |
So far I tried the following, to no avail
df3=df3.groupby(['country','cuisines'])['count'].nlargest(5).reset_index()
df3=df3[['country','cuisines']].sort_values(['count'], ascending=False).head(5)