Spotify Data Frame

Open In Colab

Below is the Spotify Data Frame that reads the file spotify_all.csv containing data of Spotify users’ playlist information (Source: Spotify Million Playlist Dataset Challenge).

import pandas as pd
from google.colab import data_table
data_table.enable_dataframe_formatter()

spotify = pd.read_csv('https://bcdanl.github.io/data/spotify_all.csv')
spotify
Warning: total number of rows (198005) exceeds max_rows (20000). Falling back to pandas display.
pid playlist_name pos artist_name track_name duration_ms album_name
0 0 Throwbacks 0 Missy Elliott Lose Control (feat. Ciara & Fat Man Scoop) 226863 The Cookbook
1 0 Throwbacks 1 Britney Spears Toxic 198800 In The Zone
2 0 Throwbacks 2 Beyoncé Crazy In Love 235933 Dangerously In Love (Alben für die Ewigkeit)
3 0 Throwbacks 3 Justin Timberlake Rock Your Body 267266 Justified
4 0 Throwbacks 4 Shaggy It Wasn't Me 227600 Hot Shot
... ... ... ... ... ... ... ...
198000 999998 ✝️ 6 Chris Tomlin Waterfall 209573 Love Ran Red
198001 999998 ✝️ 7 Chris Tomlin The Roar 220106 Love Ran Red
198002 999998 ✝️ 8 Crowder Lift Your Head Weary Sinner (Chains) 224666 Neon Steeple
198003 999998 ✝️ 9 Chris Tomlin We Fall Down 280960 How Great Is Our God: The Essential Collection
198004 999998 ✝️ 10 Caleb and Kelsey 10,000 Reasons / What a Beautiful Name 178189 10,000 Reasons / What a Beautiful Name

198005 rows × 7 columns

Variable Description

  • pid: playlist ID; unique ID for playlist
  • playlist_name: a name of playlist
  • pos: a position of the track within a playlist (starting from 0)
  • artist_name: name of the track’s primary artist
  • track_name: name of the track
  • duration_ms: duration of the track in milliseconds
  • album_name: name of the track’s album

Favorite Artist

My favorite artist in the Spotify data frame is Willie Nelson.

All of Willie Nelson’s songs in the Spotify data frame and their details are displayed below:

(
    spotify
    .set_index('artist_name')
    .loc['Willie Nelson']
)
pid playlist_name pos track_name duration_ms album_name
artist_name
Willie Nelson 9 old country 0 Highwayman 182973 Nashville Rebel
Willie Nelson 9 old country 1 Highwayman 182973 Nashville Rebel
Willie Nelson 83 Florida 66 Always On My Mind 212666 Always On My Mind
Willie Nelson 83 Florida 67 Luckenback Texas 94520 Country Outlaws
Willie Nelson 90 For the Road 67 Highwayman 182973 Nashville Rebel
... ... ... ... ... ... ...
Willie Nelson 999873 dads 2 I Gotta Get Drunk 129759 Walking the Line
Willie Nelson 999873 dads 6 Pancho and Lefty 286066 Walking the Line
Willie Nelson 999873 dads 45 Seven Spanish Angels (With Ray Charles) 229533 Half Nelson
Willie Nelson 999897 Kings 153 On the Road Again 153106 Greatest Hits (& Some That Will Be)
Willie Nelson 999936 Road Trip 67 On the Road Again 153106 Greatest Hits (& Some That Will Be)

62 rows × 6 columns

Number of Songs

willie_nelson = (
    spotify
    .set_index('artist_name')
    .loc['Willie Nelson']
)
len(willie_nelson)
62

There are 62 Willie Nelson songs in this data frame.

Longest Song

(
    willie_nelson
    .sort_values(['duration_ms'], ascending = False)
    .head(1)
)
pid playlist_name pos track_name duration_ms album_name
artist_name
Willie Nelson 114 Willie 13 Sunday Mornin' Comin' Down 422173 Willie Nelson Sings Kristofferson

The longest Willie Nelson song in this data set is “Sunday Mornin’ Comin’ Down” at 422173 milliseconds.

Shortest Song

(
    willie_nelson
    .sort_values(['duration_ms'], ascending = True)
    .head(1)
)
pid playlist_name pos track_name duration_ms album_name
artist_name
Willie Nelson 83 Florida 67 Luckenback Texas 94520 Country Outlaws

The shortest Willie Nelson song is “Luckenback Texas” at 94520 milliseconds.

Songs between 150000 and 200000 ms in the “Willie” playlist

Below are all songs in the “Willie” playlist that are greater than 150000 ms but less than 200000 ms:

greater_than_15 = willie_nelson['duration_ms'] > 150000
less_than_20 = willie_nelson['duration_ms'] < 200000
willie_playlist = willie_nelson['playlist_name'] == 'Willie'
willie_nelson[greater_than_15 & less_than_20 & willie_playlist]
pid playlist_name pos track_name duration_ms album_name
artist_name
Willie Nelson 114 Willie 1 Little House on the Hill 182080 God's Problem Child
Willie Nelson 114 Willie 3 Nothing I Can Do About It Now 199160 A Horse Called Music
Willie Nelson 114 Willie 8 Night Life 197813 For the Good Times: A Tribute to Ray Price
Willie Nelson 114 Willie 10 If You Can Touch Her At All 183866 Funny How Time Slips Away - The Best Of
Willie Nelson 114 Willie 11 Stay All Night (Stay A Little Longer) 154160 Shotgun Willie
Willie Nelson 114 Willie 12 Sad Songs And Waltzes 185213 Shotgun Willie
Willie Nelson 114 Willie 19 Fly Me To The Moon 169960 American Classic
Willie Nelson 114 Willie 21 Mona Lisa 151826 Somewhere over the Rainbow
Willie Nelson 114 Willie 22 Texas On A Saturday Night (With Mel Tillis) 159533 Half Nelson
willie_songs = willie_nelson[greater_than_15 & less_than_20 & willie_playlist]
len(willie_songs)
9

There are 9 songs in the “Willie” playlist within this range.