listening-analysis/analysis.ipynb

896 lines
263 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Listening Analysis\n",
"\n",
"Combining Spotify & Last.fm data for exploring habits and trends\n",
"Uses two data sources,\n",
"\n",
"1. Last.fm scrobbles\n",
"2. Spotify audio features\n",
"\n",
"The two are joined by searching Last.fm tracks on Spotify to get a Uri, the track name and artist name are provided for the query.\n",
2021-02-04 13:34:25 +00:00
"These Uris can be used to retrieve Spotify feature descriptors. `all_joined()` gets a BigQuery of that joins the scrobble time series with their audio features and provides this as a panda frame.\n",
"\n",
"Explorations are made from [album](./album.ipynb), [artist](./artist.ipynb) and [playlist](./playlist.ipynb) perspectives. "
]
},
{
"cell_type": "code",
2021-02-01 21:43:27 +00:00
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"track object\n",
"album object\n",
"artist object\n",
"uri object\n",
"acousticness float64\n",
"danceability float64\n",
"duration_ms float64\n",
"energy float64\n",
"instrumentalness float64\n",
"key float64\n",
"liveness float64\n",
"loudness float64\n",
"mode float64\n",
"speechiness float64\n",
"tempo float64\n",
"time_signature float64\n",
"valence float64\n",
"dtype: object"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scrobbles.dtypes"
]
},
2021-02-04 13:34:25 +00:00
{
"cell_type": "markdown",
"metadata": {},
2021-02-04 13:34:25 +00:00
"source": [
"# Spotify Descriptor\n",
"\n",
"The Spotify API provides access to various characteristics about a track, they are used here for exploring listening habits. The descriptions from the [Spotify API Documentation](https://developer.spotify.com/documentation/web-api/reference/#object-audiofeaturesobject) can be seen below:\n",
"\n",
"### acousticness\n",
"A confidence measure from 0.0 to 1.0 of whether the track is acoustic. 1.0 represents high confidence the track is acoustic.\n",
"\n",
"### danceability\n",
"Danceability describes how suitable a track is for dancing based on a combination of musical elements including tempo, rhythm stability, beat strength, and overall regularity. A value of 0.0 is least danceable and 1.0 is most danceable.\n",
"\n",
"### energy\n",
"Energy is a measure from 0.0 to 1.0 and represents a perceptual measure of intensity and activity. Typically, energetic tracks feel fast, loud, and noisy. For example, death metal has high energy, while a Bach prelude scores low on the scale. Perceptual features contributing to this attribute include dynamic range, perceived loudness, timbre, onset rate, and general entropy.\n",
"\n",
"### instrumentalness\n",
"Predicts whether a track contains no vocals. “Ooh” and “aah” sounds are treated as instrumental in this context. Rap or spoken word tracks are clearly “vocal”. The closer the instrumentalness value is to 1.0, the greater likelihood the track contains no vocal content. Values above 0.5 are intended to represent instrumental tracks, but confidence is higher as the value approaches 1.0.\n",
"\n",
"### key\n",
"The key the track is in. Integers map to pitches using standard Pitch Class notation . E.g. 0 = C, 1 = C♯/D♭, 2 = D, and so on.\n",
"\n",
"### liveness\n",
"Detects the presence of an audience in the recording. Higher liveness values represent an increased probability that the track was performed live. A value above 0.8 provides strong likelihood that the track is live. \tFloat\n",
"\n",
"### loudness\n",
"The overall loudness of a track in decibels (dB). Loudness values are averaged across the entire track and are useful for comparing relative loudness of tracks. Loudness is the quality of a sound that is the primary psychological correlate of physical strength (amplitude). Values typical range between -60 and 0 db.\n",
"\n",
"### mode\n",
"Mode indicates the modality (major or minor) of a track, the type of scale from which its melodic content is derived. Major is represented by 1 and minor is 0.\n",
"\n",
"### speechiness\n",
"Speechiness detects the presence of spoken words in a track. The more exclusively speech-like the recording (e.g. talk show, audio book, poetry), the closer to 1.0 the attribute value. Values above 0.66 describe tracks that are probably made entirely of spoken words. Values between 0.33 and 0.66 describe tracks that may contain both music and speech, either in sections or layered, including such cases as rap music. Values below 0.33 most likely represent music and other non-speech-like tracks.\n",
"\n",
"### tempo\n",
"The overall estimated tempo of a track in beats per minute (BPM). In musical terminology, tempo is the speed or pace of a given piece and derives directly from the average beat duration.\n",
"\n",
"### time_signature\n",
"An estimated overall time signature of a track. The time signature (meter) is a notational convention to specify how many beats are in each bar (or measure).\n",
"\n",
"### valence\n",
"A measure from 0.0 to 1.0 describing the musical positiveness conveyed by a track. Tracks with high valence sound more positive (e.g. happy, cheerful, euphoric), while tracks with low valence sound more negative (e.g. sad, depressed, angry)."
]
2021-02-04 13:34:25 +00:00
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>acousticness</th>\n",
" <th>danceability</th>\n",
" <th>duration_ms</th>\n",
" <th>energy</th>\n",
" <th>instrumentalness</th>\n",
" <th>key</th>\n",
" <th>liveness</th>\n",
" <th>loudness</th>\n",
" <th>mode</th>\n",
" <th>speechiness</th>\n",
" <th>tempo</th>\n",
" <th>time_signature</th>\n",
" <th>valence</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>mean</th>\n",
2021-05-07 01:03:08 +01:00
" <td>0.178143</td>\n",
" <td>0.589393</td>\n",
" <td>2.430387e+05</td>\n",
" <td>0.704151</td>\n",
" <td>0.238050</td>\n",
" <td>5.323999</td>\n",
" <td>0.212907</td>\n",
" <td>-7.321487</td>\n",
" <td>0.570426</td>\n",
" <td>0.144195</td>\n",
" <td>124.301787</td>\n",
" <td>3.954734</td>\n",
" <td>0.416501</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
2021-05-07 01:03:08 +01:00
" <td>0.254707</td>\n",
" <td>0.173309</td>\n",
" <td>1.251593e+05</td>\n",
" <td>0.210795</td>\n",
" <td>0.349545</td>\n",
" <td>3.673897</td>\n",
" <td>0.170618</td>\n",
" <td>3.805300</td>\n",
" <td>0.495018</td>\n",
" <td>0.135663</td>\n",
" <td>30.824885</td>\n",
" <td>0.370057</td>\n",
" <td>0.238092</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>2.982700e+04</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-60.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
2021-05-07 01:03:08 +01:00
" <td>0.004340</td>\n",
" <td>0.472000</td>\n",
" <td>1.875410e+05</td>\n",
" <td>0.576000</td>\n",
" <td>0.000001</td>\n",
" <td>2.000000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.099100</td>\n",
" <td>-8.837000</td>\n",
" <td>0.000000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.047100</td>\n",
" <td>97.215000</td>\n",
" <td>4.000000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.218000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
2021-05-07 01:03:08 +01:00
" <td>0.047300</td>\n",
" <td>0.601000</td>\n",
" <td>2.266320e+05</td>\n",
" <td>0.742000</td>\n",
" <td>0.002100</td>\n",
" <td>6.000000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.139000</td>\n",
" <td>-6.617000</td>\n",
" <td>1.000000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.078400</td>\n",
" <td>124.985000</td>\n",
" <td>4.000000</td>\n",
" <td>0.396000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
2021-05-07 01:03:08 +01:00
" <td>0.250000</td>\n",
" <td>0.722000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>2.822180e+05</td>\n",
" <td>0.874000</td>\n",
" <td>0.528000</td>\n",
" <td>9.000000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.292000</td>\n",
" <td>-4.890000</td>\n",
" <td>1.000000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.216000</td>\n",
" <td>142.899000</td>\n",
" <td>4.000000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.596000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>0.996000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.979000</td>\n",
" <td>4.995315e+06</td>\n",
" <td>0.999000</td>\n",
" <td>0.995000</td>\n",
" <td>11.000000</td>\n",
" <td>0.995000</td>\n",
" <td>3.108000</td>\n",
" <td>1.000000</td>\n",
" <td>0.966000</td>\n",
" <td>248.028000</td>\n",
" <td>5.000000</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.988000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" acousticness danceability duration_ms energy instrumentalness \\\n",
2021-05-07 01:03:08 +01:00
"mean 0.178143 0.589393 2.430387e+05 0.704151 0.238050 \n",
"std 0.254707 0.173309 1.251593e+05 0.210795 0.349545 \n",
"min 0.000000 0.000000 2.982700e+04 0.000000 0.000000 \n",
"25% 0.004340 0.472000 1.875410e+05 0.576000 0.000001 \n",
"50% 0.047300 0.601000 2.266320e+05 0.742000 0.002100 \n",
"75% 0.250000 0.722000 2.822180e+05 0.874000 0.528000 \n",
"max 0.996000 0.979000 4.995315e+06 0.999000 0.995000 \n",
"\n",
" key liveness loudness mode speechiness tempo \\\n",
2021-05-07 01:03:08 +01:00
"mean 5.323999 0.212907 -7.321487 0.570426 0.144195 124.301787 \n",
"std 3.673897 0.170618 3.805300 0.495018 0.135663 30.824885 \n",
"min 0.000000 0.000000 -60.000000 0.000000 0.000000 0.000000 \n",
2021-05-07 01:03:08 +01:00
"25% 2.000000 0.099100 -8.837000 0.000000 0.047100 97.215000 \n",
"50% 6.000000 0.139000 -6.617000 1.000000 0.078400 124.985000 \n",
"75% 9.000000 0.292000 -4.890000 1.000000 0.216000 142.899000 \n",
"max 11.000000 0.995000 3.108000 1.000000 0.966000 248.028000 \n",
"\n",
" time_signature valence \n",
2021-05-07 01:03:08 +01:00
"mean 3.954734 0.416501 \n",
"std 0.370057 0.238092 \n",
"min 0.000000 0.000000 \n",
2021-05-07 01:03:08 +01:00
"25% 4.000000 0.218000 \n",
"50% 4.000000 0.396000 \n",
2021-05-07 01:03:08 +01:00
"75% 4.000000 0.596000 \n",
"max 5.000000 0.988000 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scrobbles.describe()[1:]"
]
},
{
"cell_type": "code",
2021-02-01 21:43:27 +00:00
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>track</th>\n",
" <th>album</th>\n",
" <th>artist</th>\n",
" <th>uri</th>\n",
" <th>acousticness</th>\n",
" <th>danceability</th>\n",
" <th>duration_ms</th>\n",
" <th>energy</th>\n",
" <th>instrumentalness</th>\n",
" <th>key</th>\n",
" <th>liveness</th>\n",
" <th>loudness</th>\n",
" <th>mode</th>\n",
" <th>speechiness</th>\n",
" <th>tempo</th>\n",
" <th>time_signature</th>\n",
" <th>valence</th>\n",
" </tr>\n",
" <tr>\n",
" <th>time</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
2021-05-07 01:03:08 +01:00
" <th>2021-05-06 22:22:59+00:00</th>\n",
" <td>The Enemy (feat. Fat Joe)</td>\n",
" <td>The Big Picture</td>\n",
" <td>Big L</td>\n",
" <td>spotify:track:27GWWBegMtuzYixG9JTNrW</td>\n",
" <td>0.11500</td>\n",
" <td>0.600</td>\n",
" <td>168013.0</td>\n",
" <td>0.649</td>\n",
" <td>0.000190</td>\n",
" <td>11.0</td>\n",
" <td>0.8240</td>\n",
" <td>-8.372</td>\n",
" <td>1.0</td>\n",
" <td>0.3930</td>\n",
" <td>174.130</td>\n",
" <td>4.0</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.8770</td>\n",
" </tr>\n",
" <tr>\n",
2021-05-07 01:03:08 +01:00
" <th>2021-05-06 22:21:00+00:00</th>\n",
" <td>Running Up Freestyle</td>\n",
" <td>Fever</td>\n",
" <td>Megan Thee Stallion</td>\n",
" <td>spotify:track:1YU0fHUCpUyxkWqxx9ivHK</td>\n",
" <td>0.00825</td>\n",
" <td>0.917</td>\n",
" <td>124803.0</td>\n",
" <td>0.897</td>\n",
" <td>0.000000</td>\n",
" <td>10.0</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.2390</td>\n",
" <td>-2.297</td>\n",
" <td>0.0</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.1190</td>\n",
" <td>92.975</td>\n",
" <td>4.0</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.3100</td>\n",
" </tr>\n",
" <tr>\n",
2021-05-07 01:03:08 +01:00
" <th>2021-05-06 22:15:15+00:00</th>\n",
" <td>m.A.A.d city</td>\n",
" <td>good kid, m.A.A.d city (Deluxe)</td>\n",
" <td>Kendrick Lamar</td>\n",
" <td>spotify:track:3qX1dqmDdmMvvfMVfsx4Bh</td>\n",
" <td>0.05380</td>\n",
" <td>0.487</td>\n",
" <td>350120.0</td>\n",
" <td>0.729</td>\n",
" <td>0.000004</td>\n",
" <td>2.0</td>\n",
" <td>0.4400</td>\n",
" <td>-6.815</td>\n",
" <td>1.0</td>\n",
" <td>0.2710</td>\n",
" <td>91.048</td>\n",
" <td>4.0</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.2170</td>\n",
" </tr>\n",
" <tr>\n",
2021-05-07 01:03:08 +01:00
" <th>2021-05-06 22:12:13+00:00</th>\n",
" <td>Pony</td>\n",
" <td>House Party</td>\n",
" <td>Valentino Khan</td>\n",
" <td>spotify:track:26AIHH0JMIP8sd7YBM5uWb</td>\n",
" <td>0.00027</td>\n",
" <td>0.803</td>\n",
" <td>210937.0</td>\n",
" <td>0.984</td>\n",
" <td>0.846000</td>\n",
" <td>1.0</td>\n",
" <td>0.0434</td>\n",
" <td>-3.930</td>\n",
" <td>1.0</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.0548</td>\n",
" <td>127.994</td>\n",
" <td>4.0</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.3710</td>\n",
" </tr>\n",
" <tr>\n",
2021-05-07 01:03:08 +01:00
" <th>2021-05-06 22:07:57+00:00</th>\n",
" <td>Pull The Trigga</td>\n",
" <td>UKF Bass Culture 4</td>\n",
" <td>Dommix</td>\n",
" <td>spotify:track:0A0NjGXyHELTlBeMZcMyxZ</td>\n",
" <td>0.00825</td>\n",
" <td>0.789</td>\n",
" <td>260930.0</td>\n",
" <td>0.891</td>\n",
" <td>0.798000</td>\n",
" <td>9.0</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.8610</td>\n",
" <td>-5.975</td>\n",
" <td>1.0</td>\n",
" <td>0.1030</td>\n",
" <td>129.029</td>\n",
" <td>4.0</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.4100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2017-11-03 03:28:51+00:00</th>\n",
" <td>Site Zero / The Vault</td>\n",
" <td>Void</td>\n",
" <td>RL Grime</td>\n",
" <td>spotify:track:762ME2OHjuGo4xTbfZhpok</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.68300</td>\n",
" <td>0.289</td>\n",
" <td>464015.0</td>\n",
" <td>0.404</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.854000</td>\n",
" <td>7.0</td>\n",
" <td>0.3280</td>\n",
" <td>-12.815</td>\n",
" <td>0.0</td>\n",
" <td>0.0352</td>\n",
" <td>92.873</td>\n",
" <td>4.0</td>\n",
" <td>0.0285</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2017-11-03 02:54:37+00:00</th>\n",
" <td>Reminder (feat. How To Dress Well)</td>\n",
" <td>Void</td>\n",
" <td>RL Grime</td>\n",
" <td>spotify:track:2JUdMBlA5JzuemLGzZNDrf</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.68300</td>\n",
" <td>0.593</td>\n",
" <td>260075.0</td>\n",
" <td>0.560</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.109000</td>\n",
" <td>3.0</td>\n",
" <td>0.1040</td>\n",
" <td>-7.059</td>\n",
" <td>0.0</td>\n",
" <td>0.0447</td>\n",
" <td>113.895</td>\n",
" <td>4.0</td>\n",
" <td>0.3630</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2017-11-03 02:50:23+00:00</th>\n",
" <td>Monsoon</td>\n",
" <td>Void</td>\n",
" <td>RL Grime</td>\n",
" <td>spotify:track:0jYAtTuRsRdHMuvaOXIAj5</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.03460</td>\n",
" <td>0.546</td>\n",
" <td>254815.0</td>\n",
" <td>0.850</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.680000</td>\n",
" <td>10.0</td>\n",
" <td>0.1120</td>\n",
" <td>-3.366</td>\n",
" <td>0.0</td>\n",
" <td>0.0386</td>\n",
" <td>161.996</td>\n",
" <td>4.0</td>\n",
" <td>0.3020</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2017-11-03 02:46:26+00:00</th>\n",
" <td>Core - Original Mix</td>\n",
" <td>Void</td>\n",
" <td>RL Grime</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2017-11-03 02:43:01+00:00</th>\n",
" <td>Let Go (interlude)</td>\n",
" <td>Void</td>\n",
" <td>RL Grime</td>\n",
" <td>spotify:track:39FvWuHBtYQTJNdisJxZIG</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.18100</td>\n",
" <td>0.361</td>\n",
" <td>153346.0</td>\n",
" <td>0.727</td>\n",
2021-05-07 01:03:08 +01:00
" <td>0.710000</td>\n",
" <td>7.0</td>\n",
" <td>0.1980</td>\n",
" <td>-8.480</td>\n",
" <td>1.0</td>\n",
" <td>0.0519</td>\n",
" <td>104.380</td>\n",
" <td>4.0</td>\n",
" <td>0.0368</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
2021-05-07 01:03:08 +01:00
"<p>94847 rows × 17 columns</p>\n",
"</div>"
],
"text/plain": [
2021-02-01 21:43:27 +00:00
" track \\\n",
"time \n",
2021-05-07 01:03:08 +01:00
"2021-05-06 22:22:59+00:00 The Enemy (feat. Fat Joe) \n",
"2021-05-06 22:21:00+00:00 Running Up Freestyle \n",
"2021-05-06 22:15:15+00:00 m.A.A.d city \n",
"2021-05-06 22:12:13+00:00 Pony \n",
"2021-05-06 22:07:57+00:00 Pull The Trigga \n",
2021-02-01 21:43:27 +00:00
"... ... \n",
"2017-11-03 03:28:51+00:00 Site Zero / The Vault \n",
"2017-11-03 02:54:37+00:00 Reminder (feat. How To Dress Well) \n",
"2017-11-03 02:50:23+00:00 Monsoon \n",
"2017-11-03 02:46:26+00:00 Core - Original Mix \n",
2021-02-01 21:43:27 +00:00
"2017-11-03 02:43:01+00:00 Let Go (interlude) \n",
"\n",
2021-05-07 01:03:08 +01:00
" album \\\n",
"time \n",
"2021-05-06 22:22:59+00:00 The Big Picture \n",
"2021-05-06 22:21:00+00:00 Fever \n",
"2021-05-06 22:15:15+00:00 good kid, m.A.A.d city (Deluxe) \n",
"2021-05-06 22:12:13+00:00 House Party \n",
"2021-05-06 22:07:57+00:00 UKF Bass Culture 4 \n",
"... ... \n",
"2017-11-03 03:28:51+00:00 Void \n",
"2017-11-03 02:54:37+00:00 Void \n",
"2017-11-03 02:50:23+00:00 Void \n",
"2017-11-03 02:46:26+00:00 Void \n",
"2017-11-03 02:43:01+00:00 Void \n",
"\n",
2021-05-07 01:03:08 +01:00
" artist \\\n",
"time \n",
"2021-05-06 22:22:59+00:00 Big L \n",
"2021-05-06 22:21:00+00:00 Megan Thee Stallion \n",
"2021-05-06 22:15:15+00:00 Kendrick Lamar \n",
"2021-05-06 22:12:13+00:00 Valentino Khan \n",
"2021-05-06 22:07:57+00:00 Dommix \n",
"... ... \n",
"2017-11-03 03:28:51+00:00 RL Grime \n",
"2017-11-03 02:54:37+00:00 RL Grime \n",
"2017-11-03 02:50:23+00:00 RL Grime \n",
"2017-11-03 02:46:26+00:00 RL Grime \n",
"2017-11-03 02:43:01+00:00 RL Grime \n",
"\n",
2021-02-01 21:43:27 +00:00
" uri acousticness \\\n",
"time \n",
2021-05-07 01:03:08 +01:00
"2021-05-06 22:22:59+00:00 spotify:track:27GWWBegMtuzYixG9JTNrW 0.11500 \n",
"2021-05-06 22:21:00+00:00 spotify:track:1YU0fHUCpUyxkWqxx9ivHK 0.00825 \n",
"2021-05-06 22:15:15+00:00 spotify:track:3qX1dqmDdmMvvfMVfsx4Bh 0.05380 \n",
"2021-05-06 22:12:13+00:00 spotify:track:26AIHH0JMIP8sd7YBM5uWb 0.00027 \n",
"2021-05-06 22:07:57+00:00 spotify:track:0A0NjGXyHELTlBeMZcMyxZ 0.00825 \n",
2021-02-01 21:43:27 +00:00
"... ... ... \n",
2021-05-07 01:03:08 +01:00
"2017-11-03 03:28:51+00:00 spotify:track:762ME2OHjuGo4xTbfZhpok 0.68300 \n",
"2017-11-03 02:54:37+00:00 spotify:track:2JUdMBlA5JzuemLGzZNDrf 0.68300 \n",
"2017-11-03 02:50:23+00:00 spotify:track:0jYAtTuRsRdHMuvaOXIAj5 0.03460 \n",
"2017-11-03 02:46:26+00:00 NaN NaN \n",
2021-05-07 01:03:08 +01:00
"2017-11-03 02:43:01+00:00 spotify:track:39FvWuHBtYQTJNdisJxZIG 0.18100 \n",
"\n",
2021-02-01 21:43:27 +00:00
" danceability duration_ms energy \\\n",
"time \n",
2021-05-07 01:03:08 +01:00
"2021-05-06 22:22:59+00:00 0.600 168013.0 0.649 \n",
"2021-05-06 22:21:00+00:00 0.917 124803.0 0.897 \n",
"2021-05-06 22:15:15+00:00 0.487 350120.0 0.729 \n",
"2021-05-06 22:12:13+00:00 0.803 210937.0 0.984 \n",
"2021-05-06 22:07:57+00:00 0.789 260930.0 0.891 \n",
2021-02-01 21:43:27 +00:00
"... ... ... ... \n",
"2017-11-03 03:28:51+00:00 0.289 464015.0 0.404 \n",
"2017-11-03 02:54:37+00:00 0.593 260075.0 0.560 \n",
"2017-11-03 02:50:23+00:00 0.546 254815.0 0.850 \n",
"2017-11-03 02:46:26+00:00 NaN NaN NaN \n",
"2017-11-03 02:43:01+00:00 0.361 153346.0 0.727 \n",
"\n",
" instrumentalness key liveness loudness mode \\\n",
"time \n",
2021-05-07 01:03:08 +01:00
"2021-05-06 22:22:59+00:00 0.000190 11.0 0.8240 -8.372 1.0 \n",
"2021-05-06 22:21:00+00:00 0.000000 10.0 0.2390 -2.297 0.0 \n",
"2021-05-06 22:15:15+00:00 0.000004 2.0 0.4400 -6.815 1.0 \n",
"2021-05-06 22:12:13+00:00 0.846000 1.0 0.0434 -3.930 1.0 \n",
"2021-05-06 22:07:57+00:00 0.798000 9.0 0.8610 -5.975 1.0 \n",
"... ... ... ... ... ... \n",
2021-05-07 01:03:08 +01:00
"2017-11-03 03:28:51+00:00 0.854000 7.0 0.3280 -12.815 0.0 \n",
"2017-11-03 02:54:37+00:00 0.109000 3.0 0.1040 -7.059 0.0 \n",
"2017-11-03 02:50:23+00:00 0.680000 10.0 0.1120 -3.366 0.0 \n",
"2017-11-03 02:46:26+00:00 NaN NaN NaN NaN NaN \n",
2021-05-07 01:03:08 +01:00
"2017-11-03 02:43:01+00:00 0.710000 7.0 0.1980 -8.480 1.0 \n",
"\n",
2021-02-01 21:43:27 +00:00
" speechiness tempo time_signature valence \n",
"time \n",
2021-05-07 01:03:08 +01:00
"2021-05-06 22:22:59+00:00 0.3930 174.130 4.0 0.8770 \n",
"2021-05-06 22:21:00+00:00 0.1190 92.975 4.0 0.3100 \n",
"2021-05-06 22:15:15+00:00 0.2710 91.048 4.0 0.2170 \n",
"2021-05-06 22:12:13+00:00 0.0548 127.994 4.0 0.3710 \n",
"2021-05-06 22:07:57+00:00 0.1030 129.029 4.0 0.4100 \n",
2021-02-01 21:43:27 +00:00
"... ... ... ... ... \n",
"2017-11-03 03:28:51+00:00 0.0352 92.873 4.0 0.0285 \n",
"2017-11-03 02:54:37+00:00 0.0447 113.895 4.0 0.3630 \n",
"2017-11-03 02:50:23+00:00 0.0386 161.996 4.0 0.3020 \n",
"2017-11-03 02:46:26+00:00 NaN NaN NaN NaN \n",
"2017-11-03 02:43:01+00:00 0.0519 104.380 4.0 0.0368 \n",
"\n",
2021-05-07 01:03:08 +01:00
"[94847 rows x 17 columns]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2021-02-01 21:43:27 +00:00
"scrobbles.sort_index(ascending=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# What does my listening *\"palette\"* look like over time "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
2021-05-07 01:03:08 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmwAAAHmCAYAAADOVtIGAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAABJ0AAASdAHeZh94AAEAAElEQVR4nOydd3wURRuAn7lLryS0UBN67x2R3kQERBBsgCiCin6oiF1R7GLDAoIoYENBlI7Se5ESeofQe0kn7eb7Y5KQ3O4ll57APPzud2R2dna23O67bxVSSjQajUaj0Wg0hRdLQU9Ao9FoNBqNRpMxWmDTaDQajUajKeRogU2j0Wg0Go2mkKMFNo1Go9FoNJpCjhbYNBqNRqPRaAo5WmDTaDQajUajKeRogU2j0Wg0Go2mkKMFNo1Go9FoNJpCjhbYNBqNRqPRaAo5WmDTaDQajUajKeRogU2j0Wg0Go2mkKMFNk2hQQghhRCrCnoe2UUIEZK8D9MKei65gRBilRBCFxvORYQQ7ZOvkbF5NP7Y5PHb58X4mqyhf0Oa3EQLbJo8Jfnhkec3rFtNWMoLhBDeQohRQogVQoiLQoh4IcR1IcQWIcR7QojKBT3H/EYIESaECCvoeTiLEGJI8nU+pKDn4gxCiM5CiN+FECeFEDeSr7f/hBBvCSECCnp+zpLmuDv9Keg5a249XAp6AhpNGmoBMQU9iRxwBrUP4QU9EXuEEC2B2UA54DSwCDgLeAONgJeAF4UQLaWU2wtsorc+W1DXyOU8Gv9rYCZwMo/GdwohhDvwPfAwEAssBg4BPkBHYCwwUghxn5RyTUHNMwuEAm/btYUAg4ETwDQH6w0CvPJqUprbCy2waQoNUsoDB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Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2021-02-01 21:43:27 +00:00
"# select only descriptor float columns\n",
"filtered_scrobbles = scrobbles.loc[:, float_headers]\n",
"# resample by month and mean\n",
"filtered_scrobbles = filtered_scrobbles.resample(\"3W\").mean()\n",
"\n",
"# filtered_scrobbles[\"instrumentalness\"].plot()\n",
"filtered_scrobbles.plot(linewidth=3)\n",
"\n",
"plt.title(f'Listening Characteristics Over Time')\n",
"plt.legend(loc = \"upper right\", fontsize = \"xx-small\")\n",
"plt.ylim([0, 1])\n",
"plt.grid()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# How much music do I listen to each day?"
]
},
{
"cell_type": "code",
2021-05-07 01:03:08 +01:00
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
2021-05-07 01:03:08 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAy4AAAHmCAYAAACVl9pbAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAABJ0AAASdAHeZh94AAEAAElEQVR4nOydd5gb1dXG36u6q+32rntvmGKKDaYXEwKkQUgPCekJCYQvCUlID+m9kEZCDSSQBELvEIMBd2Pce7e3912tyqrN/f4YaS1pzh2NtNpdaff8nmcfw8xo5mo0c+8995z3HCGlBMMwDMMwDMMwTCFjG+kGMAzDMAzDMAzDZIINF4ZhGIZhGIZhCh42XBiGYRiGYRiGKXjYcGEYhmEYhmEYpuBhw4VhGIZhGIZhmIKHDReGYRiGYRiGYQoeNlwYhmEYhmEYhil42HBhGIZhGIZhGKbgYcOFYRiGYRiGYZiChw0XhmEYhmEYhmEKHjZcGIZhGIZhGIYpeNhwYRiGGUMIIY4IIY6kbfuEEEIKIT4xMq0aPEKIH8S/wyUj3ZbRQvx+vjrS7WAYhknAhgvDMGOG+ERMZjjmSPy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uFBK+UgO5zTjdugFBmdDF+bfBGBBfPsZydnFpJS7oa+kt0CfcP8YSel04xPzi+Pn6MDx+7cMeirpr8S/x4gTz3B1DfT2O6G3+WroxTW/GD+MylBmxmHooWfd0A2OD0AP03q7TCs+GW/DjdCfmbXQn6GboRsXVdCft9uyvD5J/Lu+H3oiABv073cVdMPoA4qPfQ/6sxeEHvb1HujZ35ZCN7DMuA+60dcP/X4yDMNkheAshAz
"text/plain": [
"<Figure size 960x480 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2021-05-07 01:03:08 +01:00
"by_day = scrobbles[\"duration_ms\"].sort_index(ascending=True)[\"2017\":\"2022\"].resample(\"1D\").sum()\n",
"\n",
2021-05-07 01:03:08 +01:00
"years = [2017, 2022]\n",
"\n",
"# hr, min, sec, ms\n",
"ms_per_day = 24 * 60 * 60 * 1000\n",
"ms_per_hour = 60 * 60 * 1000\n",
"\n",
"listening_proportion = by_day / ms_per_hour\n",
"\n",
"lobf = np.array([])\n",
"for year in range(*years):\n",
" \n",
" year_frame = listening_proportion[str(year)]\n",
" x = np.arange(0, len(year_frame))\n",
2021-03-10 20:01:13 +00:00
" poly = Polynomial.fit(x, year_frame.to_numpy(), 4)\n",
" lobf = np.append(lobf, poly(x))\n",
"\n",
"listening_proportion = listening_proportion.reset_index() # to allow column adding\n",
"listening_proportion[\"lobf\"] = lobf # add line of best fit data here to easily resample\n",
"listening_proportion = listening_proportion.set_index('time') # set index for plotting\n",
"\n",
2021-03-10 20:01:13 +00:00
"to_display = listening_proportion.resample(\"7D\").mean() # mean requires dropping the last datapoint later\n",
"\n",
"plt.figure(figsize=(8, 4))\n",
2021-03-10 20:01:13 +00:00
"ax = to_display[\"duration_ms\"].plot(lw=3) # plot main time series\n",
"\n",
"# PLOT line of best fit\n",
"for idx, year in enumerate(range(*years)):\n",
" to_display[\"lobf\"][str(year)][:-1].plot(lw=4)\n",
"\n",
"plt.title('Hours listening per day')\n",
"plt.ylabel(\"Hours/Day\")\n",
"# plt.ylim([0, 12])\n",
"plt.grid()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2021-02-20 14:12:51 +00:00
"# Imports & Setup"
]
},
{
"cell_type": "code",
2021-03-10 20:01:13 +00:00
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
2021-02-01 21:43:27 +00:00
"from datetime import datetime\n",
"\n",
"from google.cloud import bigquery\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib as mpl\n",
2021-02-01 21:43:27 +00:00
"mpl.rcParams['figure.dpi'] = 120\n",
"\n",
"from analysis.net import get_spotnet, get_playlist, track_frame\n",
"from analysis.query import *\n",
2021-02-01 21:43:27 +00:00
"from analysis import float_headers, days_since\n",
"\n",
2021-02-01 21:43:27 +00:00
"import numpy as np\n",
"from numpy.polynomial.polynomial import Polynomial\n",
"import pandas as pd\n",
"\n",
"client = bigquery.Client()\n",
"spotnet = get_spotnet()\n",
2021-02-01 21:43:27 +00:00
"cache = 'query.csv'\n",
"first_day = datetime(year=2017, month=11, day=3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Read Scrobble Frame"
]
},
{
"cell_type": "code",
2021-03-10 20:01:13 +00:00
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"scrobbles = get_query(cache=cache)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Write Scrobble Frame"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"scrobbles.reset_index().to_csv(cache, sep='\\t')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2021-05-07 01:03:08 +01:00
"version": "3.8.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}