Lesson 2.1Module 2: Seeing patterns40 minBeginner

Has music got louder? Visualising 100 years of Spotify data

Load real data on 170,000 tracks released from 1921 to 2020, chart a century of loudness, and learn how to read a time-series chart honestly: averages versus spread, who's in the sample, and when a trend isn't what it seems.

Part of the free course Music as Data: Time Series with Python · taught by Terence D. Agbeyegbe and Tone Agbeyegbe

Ask a mastering engineer about the "loudness war" and you'll hear a story: from the 1990s, records were mastered louder and louder, squashing the difference between quiet and loud passages so that songs would jump out on the radio and in the shop. Is it true? With a century of Spotify data, you can check for yourself. This lesson is about making the charts that answer the question, and about reading them without being fooled.

The data

We'll use a public dataset of 170,653 tracks on Spotify released between 1921 and 2020, collected from Spotify's Web API before Spotify restricted access to this kind of data in 2024. For every track it gives the release year and Spotify's audio measurements, including:

  • loudness: the track's average loudness in decibels (dB). Spotify's values run from about −60 dB (very quiet) up to 0 dB (the loudest a digital file can go), so less negative means louder.
  • energy, acousticness, danceability and others: scores from 0 to 1 that Spotify computed from the audio.
  • duration_ms: the length in milliseconds.
  • popularity: Spotify's 0–100 popularity score at the time the data was collected.

Download it from Kaggle: Spotify Dataset (data.csv, data_by_year.csv and more). You need a free Kaggle account. Unzip it and put data_by_year.csv and data.csv in the folder you run Python from.

A note on decibels. Decibels are a logarithmic scale, like the log axis in lesson 1.4. An increase of 6 dB doubles the height of the waveform, and as a rough rule of thumb an increase of about 10 dB sounds about twice as loud. So a few decibels is a big change.

A first look

data_by_year.csv has one row per year: the average of every track released that year. It's already a time series.

Python
import pandas as pd
import matplotlib.pyplot as plt

years = pd.read_csv("data_by_year.csv", index_col="year")
print(years.shape)
print(years.index.min(), "to", years.index.max())
print(years["loudness"].loc[[1950, 1970, 1990, 2000, 2010, 2020]].round(1))

That's 100 years of 13 measurements. Average loudness goes from about −13.9 dB in 1950 to −6.6 dB in 2020: more than 7 dB louder. But the numbers alone don't tell you when or how it happened. For that you need a chart.

Chart 1: the trend

Python
ax = years["loudness"].plot(figsize=(10, 3.6), linewidth=2)
ax.axvspan(1991, 2008, alpha=0.12, color="C1")
ax.text(1993, -17, "1991–2008:\nthe 'loudness war'?", color="C1", fontsize=9)
ax.set_xlabel("Release year")
ax.set_ylabel("Average loudness (dB)")
ax.set_title("Average loudness of tracks on Spotify, by release year")
plt.show()
A jumpy line between about −14 and −19 dB in the 1920s, rising unevenly to about −12 dB by 1970, flat through the 1980s, then climbing steeply from 1991 to about −7 dB in 2008, and staying near there.
A jumpy line between about −14 and −19 dB in the 1920s, rising unevenly to about −12 dB by 1970, flat through the 1980s, then climbing steeply from 1991 to about −7 dB in 2008, and staying near there.

The chart tells a richer story than "music got louder":

  • Before 1950 the line is jumpy. There are far fewer tracks per year in the early decades (we'll check this below), so each yearly average rests on less data.
  • From the 1960s to 1990 loudness rises slowly, then goes flat: the 1980s average sits around −11 dB year after year.
  • From 1991 to about 2008 it climbs steeply, by about 4.5 dB in under twenty years. That's the loudness war, right where the engineers say it was.
  • After 2008 it stops rising. That's often linked to two things: a backlash among artists and listeners (Metallica's Death Magnetic, released in 2008, was widely criticised for being mastered so loud it distorted), and streaming services adjusting the playback volume of every song to a common level, which takes away the advantage of mastering louder.

A good time-series chart is mostly about these choices: one clear line, labelled axes with units, and an annotation that points the reader to the period that matters. Notice we didn't force the y-axis to start at zero. Zero dB is the ceiling, not a natural baseline, and starting there would flatten the very change we want to see.

Chart 2: the average hides the spread

A yearly average is one number standing in for up to 2,000 tracks. Did every track get louder, or just some? To see the spread, go back to the individual tracks in data.csv:

Python
tracks = pd.read_csv("data.csv", usecols=["year", "loudness", "duration_ms"])
by_year = tracks.groupby("year")["loudness"]

print("Biggest gap from data_by_year.csv:", (by_year.mean() - years["loudness"]).abs().max())

spread = pd.DataFrame({
    "p10": by_year.quantile(0.10),       # 10% of tracks are quieter than this
    "median": by_year.median(),
    "p90": by_year.quantile(0.90),       # 10% of tracks are louder than this
}).loc[1950:]
print(spread.loc[[1990, 2010]].round(1))

The first line is a check worth making whenever someone hands you a summary file: our own yearly averages match data_by_year.csv to within a rounding error, so we know exactly how it was made.

Python
fig, ax = plt.subplots(figsize=(10, 3.6))
ax.fill_between(spread.index, spread["p10"], spread["p90"], alpha=0.25, label="Middle 80% of tracks")
ax.plot(spread.index, spread["median"], linewidth=2, label="Median track")
ax.set_xlabel("Release year")
ax.set_ylabel("Loudness (dB)")
ax.set_title("Not just louder: the quiet end disappeared")
ax.legend(loc="lower right", fontsize=8)
plt.show()
A shaded band between the 10th and 90th percentiles with a median line inside. The band's top edge rises gently, while its bottom edge rises much more, so the band narrows sharply after 1990.
A shaded band between the 10th and 90th percentiles with a median line inside. The band's top edge rises gently, while its bottom edge rises much more, so the band narrows sharply after 1990.

This is the more interesting finding. The loud end of the band (the 90th percentile) rose by under 2 dB between 1990 and 2010, but the quiet end (the 10th percentile) rose by about 7 dB. Loud records didn't get much louder. Quiet records largely stopped being made quiet. That's what heavy compression does: it lifts the quiet parts up towards the loud ones. A chart of the average alone would never have shown it.

Chart 3: who's in the sample?

Before trusting any chart of a dataset over time, ask what's in each year's data:

Python
counts = tracks.groupby("year").size()

plt.figure(figsize=(10, 3))
plt.bar(counts.index, counts.values, width=0.8)
plt.xlabel("Release year")
plt.ylabel("Tracks in the dataset")
plt.title("Tracks per year: few in the early decades, then about 2,000 a year")
plt.show()

print(counts.loc[1950:].describe().round(0))
A bar chart: from under a hundred to a couple of thousand tracks a year before 1950, then an almost flat 2,000 a year from 1950 onwards.
A bar chart: from under a hundred to a couple of thousand tracks a year before 1950, then an almost flat 2,000 a year from 1950 onwards.

Before 1950 the counts swing from 71 tracks to 2,000. From 1950 on, every year has close to 2,000 tracks (68 of the 71 years are between 1,900 and 2,100, and 37 have exactly 2,000). That's not how much music was released. It's a sign that the people who built the dataset aimed for a fixed number of tracks per year. So this isn't "all music" but "a sample of the music from each year that's on Spotify today". Two consequences:

  • Survivorship. Old music on Spotify is the music somebody thought was worth putting there, often the best-known recordings. That can make the past look different from what people actually heard at the time.
  • Remasters. Many older recordings on Spotify are remastered versions, re-processed (and often made louder) years later. So some of the "1965" loudness may really be 2000s mastering. That's a measurement problem that is tied to time itself, the kind that can create or hide a trend. It means the early part of our loudness line is, if anything, probably too loud, and the real rise was likely even larger.

Chart 4: small multiples

Loudness isn't the only thing that changed. Instead of crowding several lines onto one chart with different units, draw small multiples: the same kind of chart, side by side, sharing the time axis.

Python
panels = {
    "Loudness (dB)": years["loudness"],
    "Energy (0–1)": years["energy"],
    "Acousticness (0–1)": years["acousticness"],
    "Length (minutes)": years["duration_ms"] / 60_000,
}
fig, axes = plt.subplots(2, 2, figsize=(10, 5.5), sharex=True)
for ax, (name, series) in zip(axes.flat, panels.items()):
    ax.plot(series.index, series.values, linewidth=1.8)
    ax.set_title(name, fontsize=10)
fig.suptitle("A century of change on Spotify, by release year", fontsize=11)
plt.tight_layout()
plt.show()
Four small charts. Loudness and energy rise together; acousticness falls steeply from the 1950s to the 1980s; length is jumpy before 1950, jumps above 4 minutes in the late 1960s, stays there until about 2015, then falls to 3.2 minutes by 2020.
Four small charts. Loudness and energy rise together; acousticness falls steeply from the 1950s to the 1980s; length is jumpy before 1950, jumps above 4 minutes in the late 1960s, stays there until about 2015, then falls to 3.2 minutes by 2020.

Now patterns jump out across panels:

  • Energy rises with loudness. That's partly by design: Spotify described its energy score as built from features including perceived loudness, so the two aren't independent measurements.
  • Acousticness collapses between the 1950s and the 1980s: electric instruments and studio production replaced acoustic recording.
  • Songs got longer, then shorter. Average length jumps above 4 minutes in the late 1960s and averages over 4 minutes through the 1970s, 1980s and 1990s. It eases a little in the 2000s and 2010s, then falls fast: from 3.8 minutes in 2015 to 3.2 minutes in 2020. (Some years before 1950 jump around wildly, but they rest on much thinner data.)

Small multiples work because the eye compares shapes and timing across panels without having to decode four different scales on one axis.

Chart 5: a trend that isn't real

One last chart, and a warning:

Python
ax = years["popularity"].plot(figsize=(10, 3.2), linewidth=2, color="C1")
ax.set_xlabel("Release year")
ax.set_ylabel("Average popularity (0–100)")
ax.set_title("Did music get more popular every year? No.")
plt.show()
A line rising almost steadily from near zero in the 1920s to about 64 in 2020.
A line rising almost steadily from near zero in the 1920s to about 64 in 2020.

Average popularity rises almost every decade, from near zero to 64. It would be easy to write "music has become steadily more popular". But Spotify's popularity score is based on how much a track is played now, weighted towards recent plays. It measures what people stream today, not how popular a song was in its own time. Of course a 2019 hit outscores a 1952 hit on a 2020 scale. The trend in this chart is created by how the variable is defined, not by history.

Every chart in this lesson needed the same question before it could be read: what exactly was measured, when, and for which tracks?

Key ideas

  • A clear time-series chart has one message, labelled axes with units, and annotations that point to the period that matters. A y-axis doesn't have to start at zero if zero isn't meaningful.
  • An average can hide what's really happening. Plot the spread (percentile bands) too.
  • Always chart how many observations sit behind each time point. Thin early data makes noisy lines.
  • Ask who's in the sample: survivorship and remastering can distort a historical trend.
  • Small multiples compare several series without crowding one chart.
  • Some trends come from how a variable is defined (like Spotify popularity), not from what happened.

Try it yourself

  1. Plot danceability and speechiness by year. What happens around 2020, and what kind of music might explain it?
  2. Redo the spread chart for song length (duration_ms). Is the shortening in the streaming era driven by the longest songs disappearing, or by every song getting shorter?
  3. The dataset's data_by_genres.csv has averages by genre. Find the ten loudest genres. Does anything surprise you?
  4. Find the loudest year in the whole dataset. Then smooth the series with a 5-year rolling average (years["loudness"].rolling(5, center=True).mean()) and find its peak. Why do the two answers differ? (Smoothing is the subject of lesson 2.2.)

Next lesson: Trend, seasonality and noise: the Christmas song that comes back every year. Ten years of daily data, pulled apart into its three ingredients.

The course

Music as Data: Time Series with Python

Course home
  1. 1Music as a time series

  2. 2Seeing patterns

  3. 3Decomposition and stationarity

  4. 4Testing a time series

  5. 5Missing values

    • 5.1Handling missing values in music data coming soon
  6. 6Autocorrelation and forecasting

    • 6.1Autocorrelation: finding the beat coming soon
    • 6.2Partial autocorrelation and lag plots coming soon
    • 6.3How forecastable is a hit? coming soon
  7. 7Smoothing and Granger causality

    • 7.1Smoothing: moving averages and loudness envelopes coming soon
    • 7.2Granger causality: does social-media buzz predict streams? coming soon
  8. 8From time series to AI music

    • 8.1From forecasting to generating: how AI music models predict what comes next coming soon