BuildlyBuildly
DashboardExercisesProfileHelp
Data Science/Module 2: Data Analytics/Sort & Rank1/3
Exercise·7 min·10 XP

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.

Previous
Sort by Column (Descending)
Next
Sort by Multiple Columns