Analyzing Drake’s Discography

Drake is a Canadian rapper, singer, songwriter, actor, and entrepreneur. A prominent figure in popular music, Drake is credited for popularizing the Toronto sound. In 2006, Drake launched his music career by releasing his first mix tape, “Room for Improvement”. Three years later, his third mix tape, “So Far Gone”, garnered him critical and commercial success, and, the following year, he released his official debut album, “Thank Me Later”, to generally positive reviews .Drake as released 5 albums so far.

What better way to kick start my first project than to talk about my favorite artist, Drake. the reason why I like Drake is because, his music is mellow and not hardcore (main reason why I hate Rock, Punk and Metal). Thanks to his peer Noah ‘40’ Shebib, the reason behind the psychedelic vibes that his music gives.

Spotify API

While doing some research on how to gather the data I needed, I came to know that Spotify provide developers access to some of their data regarding playlists, users, and artists through their Web API called Spotify API.

Apart from track information such as track name, album, release date, length, and popularity, Spotify’s API allows us to extract a number of “audio features” such as danceability, acousticness, energy, instrumentalness, liveness, loudness, speechiness and tempo. These aspects felt like a good start to analyze Drake’s discography. As I said before, I liked the mellow vibe of Drake’s music but let’s see what these data has to say.

To start off, I had to create a developer account. By creating a client ID after logging into my Spotify account, I got a client ID and a Client Secret Key which I can use to to gain access to the data. One easy way to gather data is to create a playlist and all the tracks that you want to gather data of to it. I choose this way because it’s easy to loop through each track in a playlist rather than requesting each album of an artist from Spotify and looping through it. So I quickly created a playlist and added all the Drake’s album to it.

The Main Part (Code)

The following codes are obtained from Spotipy GitHub.

Importing Libraries

I started off by calling the necessary libraries that I needed. they are Spotipy, and Pandas.

Pandas will help assemble the data into a data frame to clean and analyze it.

Spotipy is “a lightweight Python library for the Spotify Web API”. With Spotipy, we can get full access to all of the music data provided by the Spotify platform.

Connecting to the API

To authenticate and connect to Spotify’s API, we need our “Client ID” and “Client Secret”.

client_id = 'xxx'
client_secret = 'yyy'

client_credentials_manager = SpotifyClientCredentials(client_id, client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

Retrieve IDs for each track

The below function will create an ID to each track.

def getTrackIDs(user, playlist_id):
ids = []
playlist = sp.user_playlist(user, playlist_id)
for item in playlist['tracks']['items']:
track = item['track']
ids.append(track['id'])
return ids

ids = getTrackIDs('c8ztbhj7n5pt845269o943od1', '3vhjRKRHvRPZpPVbbnUbMB')

sp.user_playlist is an inbuilt function in Spotipy to link the user and their playlist. The two parameters in the getTrackIDs are my username and playlist ID respectively.

def getTrackFeatures(id):
meta = sp.track(id)
features = sp.audio_features(id)

album = meta['album']['name']
release date = meta['album']['release date']

acousticness = features[0]['acousticness']
danceability = features[0]['danceability']

the above function gathers the track’s meta and feature data.

tracks = []
for i in range(len(ids)):
track = getTrackFeatures(ids[i])
tracks.append(track)

the above code loops over to gather data of every song’s detail and it’s stored in an array.

df = pd.DataFrame(tracks, columns = ['album', 'release_date', 'danceability', 'acousticness', 'danceability', 'energy', 'instrumentalness', 'liveness', 'loudness', 'speechiness', 'tempo'])
df.to_csv("spotify.csv", sep = ',')

using Pandas, the data are stored as a data frame and it’s saved as a .csv file.

The raw data looks like this

One problem you can witness here is that, the release_date is in two different format and I wanted it to be only year.

I initially tried to clean the data importing datetime and selecting only the year part and met with a type error. Turns out you cannot just copy paste code from Stack Overflow and expect it to work.

import datetime
year = datetime.date.today().year

TypeError: list indices must be integers or slices, not str

The initial data type for “release_date” was object and so I had to convert it into datetime using pandas and then select the year part from it.

Final_New_Dates = pd.to_datetime(Data['release_date']).dt.year

Now that the data frame is proper we can proceed to perform some analysis with the details we have.

Danceability vs Loudness

In the above graph, when comparing the danceability and loudness, there is no correlation between them which is surprisingly unexpected. I would definitely dance to tracks like “Crew Love”, “Lord Knows”, “HYFR” and “We’ll Be Fine” in shower but the graph has a different story to say.

Speechiness

This graph clearly explains the drop in BPM (Bars Per Minute lol) has the years gone by. In his early albums Drake managed to draw a lot of fan base due to his ability to rap. But in his last couple of albums he has tend to switch to a more mellow vibe. His Jamaican inspired album “Views” and UK inspired album “More Life” could be the reason to this drop in speechiness.

The tempo also dropped in his last albums. the huge spike you see in 2011 is when his hugely acclaimed album “Take Care” released, the only album even his haters cannot avoid. The lowest you see in 2013 is when his album “Nothing Was The Same” released, my most favorite album of his.

Limitations

One major limitation I met with is, I couldn’t the get data of his last album and I couldn’t figure out why. Another limitation is, unfortunately Spotify does not allow developers to get the streaming data of any songs other than popularity.

--

--