Top 10 Songs with Deduplication
Problem
**[Asked at Billboard]**
The `plays` table contains some duplicate rows (same song/artist/play_count
appearing multiple times). Deduplicate by `(song_title, artist)` then return
the **top 10 songs by `play_count`**.
Return `song_title`, `artist`, `play_count`, ordered by play_count descending.
Input data
Example rows — the live problem includes the full dataset.
plays
| play_id | song_title | artist | play_count |
|---|---|---|---|
| 1 | Song A | Artist 1 | 1000 |
| 2 | Song B | Artist 2 | 2000 |
| 3 | Song A | Artist 1 | 1000 |
| 4 | Song C | Artist 3 | 800 |
| 5 | Song D | Artist 4 | 1200 |
Expected output
Your answer should return 10 rows with the columns song_title, artist, play_count.
Starter code (Pandas (Python))
import pandas as pd
def top_songs(plays: pd.DataFrame) -> pd.DataFrame:
# Your code here
return playsSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock