BuildlyBuildly
DashboardExercisesProfileHelp
Back to all

Practice: Sort & Rank

Drills tagged with this skill, unpassed first. Pass them all to mark the skill ready for scenarios.

Module 2: Data Analytics

0/3 done
Exercises (0/3)
  • 1
    Sort by Column (Descending)
    Context. Show products in order of descending revenue for a top-line report. Your task. Write sort_by_revenue_desc(df) that returns the DataFrame sorted by revenue in descending order. Example. revenues [150, 50, 200, 100] → reordered as 200, 150, 100, 50. Notes. Stable sort — equal revenues keep their original relative order. Empty df → empty df.
    7 min· 10 XP
  • 2
    Top N by Column
    Context. Pull the top N best-selling products for a quick summary. Your task. Write top_n(df, n) that returns the n rows with the largest values in the sales column, ordered from highest to lowest. Example. 5 products, n=3 → top 3 by sales. Notes. n larger than the df → returns all rows in sorted order. n=0 → empty DataFrame.
    7 min· 10 XP
  • 3
    Sort by Multiple Columns
    Context. Order students by grade (A → F), then alphabetically by name within each grade. Your task. Write sort_grade_then_name(df) that returns the DataFrame sorted by grade ascending, then name ascending. Example. grades [B, A, A, B], names [Bob, Alice, Cher, Dan] → Alice/A, Cher/A, Bob/B, Dan/B. Notes. grade is the primary key; name is the tiebreaker. Empty df → empty df.
    7 min· 10 XP