CPSC 203, 2026 W1
October 6, 2026
Given a year of charts,
What do the paths of the number ones look like?
Do most songs debut at the top? How fast do they fall?
We can quantify these things, and analyze them, but a picture will help us see if there’s anything interesting in the data.
Draw a loose sketch of how you might visualize the paths through the Hot 100 chart for all songs which hit #1.
challenge1_nb.py.We have a list of song titles that hit #1.
Now we want all rows for those songs — their complete chart history.
.isin().isin(list) method returns True for rows where the value appears in the list.
We’ve already loaded some data behind the scenes…
Our data looks like this:
| date | title | rank |
|---|---|---|
| 2025-01-04 | Song A | 1 |
| 2025-01-04 | Song B | 15 |
| 2025-01-11 | Song A | 3 |
| 2025-01-11 | Song B | 1 |
But for plotting we want
| date | Song A | Song B |
|---|---|---|
| 2025-01-04 | 1 | 15 |
| 2025-01-11 | 3 | 1 |
groupby() method organizes rows into groups. In this case, one group per (date, title) pair.
Series with a multi-level index (date, title).sum() method just extracts that row’s value.unstack() method takes the inner index level (title) and makes it into columns in a DataFrame.
STUDENT_viz_nb.py and work through “Part 1: Visualizing Chart Trajectories”.Basically the same steps as above, but gives a better idea of what kind of code we would expect you to be able to read vs write from scratch.
Does a strong debut mean a song will stick around longer?
Or do slow climbers have more staying power?
Let’s investigate with a scatter plot!
challenge2_nb.py.rename() method allows you to rename columns.toframe() method can convert a Series into a DataFrame.pd.merge() function can combine the data in two tables.Practice for yourself:
STUDENT_viz_nb.py and work through “Part 2: Staying Power”.Basically the same steps as above, but gives a better idea of what kind of code we would expect you to be able to read vs write from scratch.
| Concept | Code |
|---|---|
| Filter by condition | df[df['rank'] == 1] |
| Get unique values | df['title'].unique() |
| Filter by list | df[df['title'].isin(list)] |
| Reshape for plotting | .groupby([...]).unstack() |
| Combining tables | pd.merge() |
https://pymotw.com/2/datetime/
https://www.dataschool.io/best-python-pandas-resources/
https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf
https://queirozf.com/entries/pandas-dataframe-plot-examples-with-matplotlib-pyplot