Tidy Track Plays by Month
Problem
You are given a DataFrame `plays` with columns `play_id`, `song_title`, and `played_on` (a date string like `2010-01-16`). The same song is sometimes written with different casing or with stray leading/trailing spaces, so `'NEONRAIN'`, `'NeonRain'`, and `' nEoNrAiN '` all mean the same track.
Normalise each `song_title` by stripping outer whitespace and lower-casing it. Then count how many times each normalised track was played in each calendar month (the `YYYY-MM` prefix of `played_on`).
Return columns `track`, `month`, `plays`, sorted by `track` then `month`.
Input data
Example rows — the live problem includes the full dataset.
| play_id | song_title | played_on |
|---|---|---|
| 1 | NEONRAIN | 2010-01-16 |
| 2 | NeonRain | 2010-01-17 |
| 3 | nEoNrAiN | 2010-02-18 |
| 4 | GLASSecho | 2010-02-19 |
| 5 | GlassEcho | 2010-02-28 |
Expected output
Your answer should return 4 rows with the columns track, month, plays.
Starter code (Pandas (Python))
import pandas as pd
def tidy_track_plays_by_month(plays) -> 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