2 min read

Introduction and Data

What makes a perfect song?

While we each believe we have our own individual music tastes, the majority of us tend to like certain genres and tracks. At the end of every year, Spotify creates a playlist of the top songs globally based on the number of times the songs were streamed by users over the year.

I’m curious about what makes a song popular, what these top songs have in common, and why people like them. The motivation of this blog is to find insights and patterns behind why certain songs are so well-loved, and at the end of it, answering the big question: what makes a perfect song?

Extracting Data

The data for this analysis is extracted from Spotify’s Web API via the spotifyr package. Using my client ID from the Spotify Developer site, I gathered this data in November 2021.

The following 3 playlists were used: Top Tracks of 2018, Top Hits of 2019, and Top Tracks of 2020, all which were created by Spotify at the end of each year.

Data Cleansing

The get_playlist_audio_features from spotifyr allows us to extract the audio analysis of each track in the playlist, but the 61 variables extracted are a little bit overwhelming and needs a little bit of cleaning up.

Columns are dropped, column names cleaned up and the number of songs in each playlist standardized.

Here’s a sample of the data we’ve extracted from each playlist. The below table is data from the Top Tracks of 2020.

Dive into the analysis into this data here.