AnalystPath

Top 10 Songs with Deduplication

PandasMediumMid levelBillboard~15 min

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_idsong_titleartistplay_count
1Song AArtist 11000
2Song BArtist 22000
3Song AArtist 11000
4Song CArtist 3800
5Song DArtist 41200

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 plays

Solve 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

Related Pandas questions