Using Spotify’s API for EDA in Python: Pop vs Rap

Using Python’s SpotipyLibrary to access the Spotify API, I compared the discography of Miley Cyrus to Kendrick Lamar’s album tracks.

Brianna Lytle
4 min readApr 9, 2023

What I did:
- Accessed the Spotify API using Python’s Spotipy.
- Scraped artists albums, tracks, and audio features within the API.
- Analyzed the difference between two artists in different genres
- Wrote this blog

Spotify Web API Documentation — HERE

5 things I learned from analyzing Miley Cyrus and Kendrick Lamar's Discography

  1. Career Growth: The popularity of the artists shows the differences in their rise to stardom.
  2. Difference in Audio Patterns: There can be less predictability in audio features for Rap tracks vs. Pop.
  3. Miley Audio Evolution: Popularity of Miley’s albums isn’t driven by any specific audio features.
  4. Kendrick Audio Evolution: Kendrick’s 2016 “DAMN.” album was a catalyst for his continuous album popularity.

1.Career Growth

Popularity of the artist’s show the differences to their rise of stardom.

Miley Cyrus’ first album success is likely supported by her fandom following her from her Hannah Montana days. With some years of music experimentation, her recent Endless Summer album reigns as her most successful.

Both artists’ recent albums have been at the top of the charts since their release. Kendrick, who started his career in 2013 with “good kid, m.A.A.d city” has a larger jump of popularity growth. His 2017 album, “DAMN.” , is a marker for continuous popularity of his following albums.

Spotify’s popularity ranking of Kendrick vs. Miley’s albums

2. Track Succces in Albums

Rap listeners are more likely to show attention to album entirety vs. few select tracks.

Between the artist’s discography, Kendrick has 3 of the top 5 popular albums. Miley’s “Endless Summer Vacation” drives the highest overall popularity.

Top 5 most popular albums between Kendrick & Miley

Kendrick’s album success is likely due to his storytelling within each album. His album popularity isn’t driven by a few great songs, rather, all of the songs tend to drive similar popularity strengths. If you look at the chart below, it’s clear how close his songs have a tight spread of popularity (red dots), while some of Miley’s albums (blue dots) can have tracks that range from popularity of 1 to 80.

Spotify’s popularity ranking of Kendrick vs. Miley’s albums and tracks

3. Difference in Audio Patterns

Pop music audio features may be more predictable vs. Rap.

Audio feature relationships are more significant with pop music. Given the nature of pop music, it makes sense that Miley had more features driving danceability, energy, etc. Kendrick drove more neutral relationships between audio features while Miley had strong correlations. Kendrick’s discography is driven by his storytelling and less reliant on the features that pop music thrives on.

Heatmap of audio features

4. Miley Audio Evolution

Popularity of Miley’s albums isn’t driven by any specific audio features.

  • Her 2nd least popular album “Miley Cyrus & Her Dead Petz” (2015) drives the highest average acousticness and instrumentalness as well as the lowest energy and loudness score. This likely impacts the overall correlation we saw in point 3.
  • From 2007 to 2017, the average tempo of her album tracks dropped. The tempo of tracks began to pick up again in 2019 and stabilized with the recent 2023 album.
  • Miley showcases jumps of valence (audio positiveness) between albums.
Popularity of Tracks in Miley Cyrus Albums
Average audio features of Miley’s Albums

5. Kendrick Audio Evolution

Kendrick’s 2016 “DAMN.” album was a catalyst for his continuous album popularity.

  • “DAMN.” was a stark difference compared to his previous albums due to the drop of loudness, energy, and jump of acousticness.
  • Kendrick’s speechiness was higher in his earlier albums peaking with “DAMN.” Despite the change, it made little impact on the success of the following albums.
  • Overtime, Kendrick’s album tracks became shorter. Duration of his songs and their popularity have a negative correlation (-0.37). This shows us that some of his most successful songs are longer and his fan’s affinity towards his storytelling.
Popularity of Tracks in Kendrick Lamar’s Albums
Changes in audio features of Kendrick Lamar

Thanks for reading!

Additional details on how I set up my Spotify scraper will be published in a future blog.

Stay tuned and stay connected for more.

--

--

Responses (1)