'How to sort a multi-variate grouped data?

The data I am working with has the ratings of household services for different cities.

Running the code below groups this data based upon the services in each city and finds the total ratings for that particular service.

grouped_services_df = df.groupby(["City", "Services"])
total_ratings = grouped_services_df.agg({"Ratings": np.sum})
total_ratings

I am trying to find the highest rated service in each city. So is there a way to sort the ratings of services for each city and not for the whole grouped dataframe?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source