Spotify Top 50

An artistic look at the seven audio features of the top 50 songs in early July of 2023, using the Spotify API, Python, and Tableau.

Mia Freidenburg
9 min readOct 21, 2023

Spotify_Project_V2: An Origin Story

AKA, “Mia, how did this all start?”

It started with a goal that seemed simple enough: I wanted to retrieve the track data for songs in my personal Spotify history, so that I could analyze and explore my listening history data and compile one of those neat “My Spotify History” dashboards you see throughout the data viz community.

Well, one thing led to another, and the frustration mounted as I realized that the Spotify API has a rate limit, and would only return a certain number of requests with basic Spotify Developer capabilities.

There were various fixes here and there that I found and bookmarked, but that would take more time. I was balancing this project along with a number of other things — some paid, most not…I, like so many others, was on the job hunt at the time. (Still am, in case any recruiters are reading this..!)

So, I decided to take a step back and reevaluate the general goal. I wanted to have something to share with my network on LinkedIn and other social media (again, job hunt) — and sooner rather than later.

I vowed to return to my personal listening history, shelved the whole project, and instead tackle something a bit more manageable — the Spotify Top 50.

Note: This playlist is currently titled “Today’s Top Hits” and contains the description as being “the Hottest 50”. There are other Top 50 playlists published by Spotify, but this the one used for this project.

I already had the building blocks of what was needed from the personal streaming history project, but I still did some research for additional resources. The project article I was originally using as a guide was — unsurprisingly, I’m sure — geared towards a streaming history dashboard, and while it was quite useful, I had hit a couple of walls. On top of that, I had seen a data visualization that was essentially a grid of radar charts that was quite inspirational, and I was itching to try out something similar.

Another note: Sadly, I haven’t been able to find the inspiration viz I’m referring to — if I do ever find it, I’ll be sure to update this article.

After consulting a couple of additional resources (big shoutout to this article right here) and reviewing the code bits I’d constructed previously, I set to work, which included reframing the project goals.

For my personal organization, I like to follow the general six-step data analysis workflow I was taught.

This workflow is: frame → extract → prepare → analyze → interpret → present.

Since the goals were altered, a few of these steps were done more informally — more on that later.

(Re)Frame

The primary goal remained — get the Spotify API to work for me. Other than that, the whole project changed.

  1. I subbed out my streaming history for the Spotify Top 50 playlist.
  2. I changed the data visualization end product from an interactive dashboard to an artistic infographic of radar charts.

Why the radar charts?

Well, after seeing articles that explored the audio features ascribed to each track by Spotify, I realized there was a way to combine these two abstract ideas and give each track a visual representation through radar charts, where each vertex of the chart represents one of the features.

There are technically many audio features for each track, but there are seven of interest for this project. These are: acousticness, danceability, energy, instrumentalness, liveness, speechiness, and valence. Each of these seven features is represented by a value between 0 and 1.

Brief & Overview

  • Use the Spotify API to retrieve track and audio feature data for a playlist of songs on Spotify.
  • Create a reusable function in Python to retrieve the track data and audio features of any playlist.
  • Compile both the audio features data set and an additional data set for building the radar charts.
  • Design and build out an infographic of radar charts displaying information on the Spotify Top 50.

Extract & Prepare

Audio Feature Retrieval

I am not including the bits of code that were compiled for my personal streaming history; for all intents and purposes, this had morphed into a completely different project at this point, complete with its own project folder and files.

With that in mind, here is a look at the coding journey I took to create the reusable function. This function not only retrieves the track and audio feature data for songs on a particular playlist (using the playlist URL), it also returns this data in a digestible format.

Most gists have been truncated; if you’d like to view the full file, please follow the link available in the caption. Be warned: some outputs are looooooooong.

View full version (including outputs).

Reusable Function

After completing the aforementioned journey, I condensed these steps into one reusable function à la Sammie Jones in the article mentioned above.

Below is my reusable function in all its glory.

The Client ID and Client Secret values have been removed for security.

Data Transformation

But wait! There’s more. (RIP, Billy Mays.)

I didn’t include this step in the reusable function, as it wouldn’t make sense to have a Rank column in pretty much any other context.

Since the Spotify Top 50 playlist is organized so that the position on the playlist corresponds to the song’s current rank, it not only made sense for this dataset, but was necessary to ensure I could rank the songs properly.

Result

“But what does the result look like?”

Well, disclaimer, a little bit of extra work was done after exporting this as a CSV. If you’re really itching to see details for that bit of the process, you can view the cleaning log. Additionally, here is the data dictionary.

After those steps, this is rows 1–10 of the resulting file:

View the full dataset.

Additional Transformation for the Radar Charts Dataset

But wait! …you get it. (Last time though!)

As part of the instructions to create radar charts in Tableau courtesy of this article, I needed to mess with the data a bit and create an additional dataset.

This one would have only the:

  • Track name
  • Variable (aka, what each point of the radar chart would represent)
  • Value (aka, the value for that song’s variable)
  • (Index column)

Using the pandas.melt function, this was super easy. Check it out!

Using the pandas melt function to pivot the dataset as needed.

Result

If you’re like me, you might want a clean visual to go along with that paragraph describing what was needed. Well, ask and you shall receive…

View the full dataset.

Analyze, Interpret, & Present

I’m chunking all of these together because — as I’ve mentioned — the primary goal of this project was creative visual representation, not hardcore analysis. This section will focus a little on the construction of the charts and a lot on the dashboard compilation process…especially what I learned not to do.

Creating Radar Charts in Tableau

When it came to building the radar charts, I stuck to the article mentioned above, as the data transformation for the additional dataset was based off these instructions.

There were many articles I came across in my quest for radar chart creation, but this one took first place in terms of simplicity. That being said, to give full credit where it is due, I’ve posted a full list of the resources I compiled for this project, including the other radar chart articles.

So…what now?

After creating the first radar chart, I had a few decisions to make on how to efficiently iterate that page for the other forty-nine charts.

Oh, and I wanted to include an “Example” chart at the top — and of course, I wanted this chart to be a tad different. A bolder background line. Slightly larger text in the tooltip. So…fifty-one charts in total; fifty with the same background; one with a different one.

Oh…and I needed to figure out how to do the background in the first place.

Sigh.

So, I paused. I had achieved the radar chart creation I so desperately desired and could take a moment to consider the potential pitfalls from here on out.

First of all…what if I copied out all of the charts and then realized that I had one subtle change I wanted to make?

Spoiler alert: I did find out that there is only so much that copying and pasting the page formatting in Tableau will do. Secondary spoiler alert…it wasn’t found out in the most enjoyable of ways.

I would say second of all, but really, that “first of all” bullet point is pretty much all-encompassing. Font type and size selections, tooltip formatting, color and opacity; I wanted to have everything planned ahead and squared away before proceeding any further.

See spoiler alert above.

Compiling a Dashboard Infographic (What I Learned)

AKA, a compilation of mishaps so that you can learn from my mistakes.

  1. First and possibly foremost: The spacing of your dashboard items on the Tableau Public website may differ from what is displayed in Tableau Public Desktop application. Unfortunately, this doesn’t seem to be an issue that has one simple fix, though it has been discussed at length.

My recommendation: Upload your project to Tableau Public and hide it from your profile. Under the assumption that you are using two (or more) monitors, keep a Tableau Public window open with your project so that you can track how it will look once published online as you’re making changes to your project. Also, take advantage of the settings available in dashboard layout tab for absolute precision.
Bonus: You can see a before-and-after by duplicating the window so that the new window loads with your changes — then you can switch between the old window and the new one to view exact differences. Just don’t refresh the browser! Keep in mind if the tab is inactive for too long, it’ll refresh anyway.

2. Let’s talk about fonts. Gosh darn do I love a good custom font. However, Tableau does not necessarily feel the same way. If you’re preparing solely for an image export you’ll likely be fine, but if you plan to share it with the data community, think twice before using a font outside of this collection.

My recommendation: If, like me, you love a good custom font — or even have just one downloaded on your device — I highly recommend viewing your (hidden) project on Tableau Public using an alternative device. That way you can ensure your font isn’t suddenly showing up as Times New Roman (I speak from experience). For example, I use my work laptop, or even my phone — though if you do use mobile, you may want to disregard formatting when you are doing your font checks.

3. While we’re on the subject of mobile formatting — be sure to check on the one that is automatically created and ensure all layouts besides the standard (laptop/computer) look good.

My recommendation: There are options to customize layouts for tablets and mobile devices, but if you’d rather preserve the formatting of your masterpiece and save a lot of time and effort all at once, I recommend just deleting the phone layout so that your workbook has only one possible layout (“default”).

4. When it comes to project documentation, we know that a cleaning log is crucial, but what about an aesthetics log? Getting that perfect combination of color and opacity (and line thickness, and so on) only to have tragedy strike in the form of errant keystrokes or a software freeze. It may not happen often, but when it does…oof. And it’s so easy to avoid.

My recommendation: Keep a file in the format of your choice updated with various aesthetic specifics you’ve established for your project. I use a text file titled something like “SPOTIFY_DASHBOARD_AESTHETICS”, and this file contains things like the hex codes for colors in the palette being used (when I’m using a custom palette, which is nearly always), fonts and sizes, dashboard container dimensions…pretty much anything I might need to reference later.

5. You can use external images for parts of your dashboard infographic that you can’t insert in Tableau!

My recommendation: Use Paint for simple lines etc. — just be sure to use an appropriate size canvas, and keep in mind that you can’t rotate the image.

Spotify_Project_V3: An Ending

AKA, in conclusion…

I ended up using the top songs from early July (2023), though it’s worth mentioning that there is an entirely separate iteration of the project that pulls the songs as they were ranked in late June; code, dashboard, and all.

Why on Earth did I go back, duplicate the Jupyter Notebook and update the code, and re-pull the songs and their ranks on that fateful July 7th, you ask?

Because Taylor Swift’s Cruel Summer rose to #1 on the top 50 list, that’s why.

The cover image I threw together for Instagram.

This one’s for the Swifties! (Not the annoying ones. The reasonable ones. ☺)

View it on Tableau Public here! Or scroll to view a static image of the poster:

Curious what the rankings were in late June? Check that out here.

And if you happen to have an quick and easy fix for the Spotify API rate limit, please message me.

--

--