Premium problem101. Dense-Rank Hosts by Total Beds

Medium Locked

apartments has columns host_id, listing_id and beds.

Total the beds each host offers and return a DataFrame with columns host_id, beds and rank, where the host with the most beds ranks 1. Use a dense rank, so tied hosts share a rank and the next rank is not skipped. Sort by rank then host_id, and renumber the index from 0.

Input

   host_id  listing_id  beds
0        1          10     2
1        1          11     3
2        2          12     5
3        3          13     1
4        3          14     4
5        4          15     5

Output

   host_id  beds  rank
0        1     5     1
1        2     5     1
2        3     5     1
3        4     5     1

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)