2021-02-01 01:37:22 +00:00
{
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2021-02-03 16:08:06 +00:00
"version": "3.8.6-final"
2021-02-01 01:37:22 +00:00
},
"orig_nbformat": 2,
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
"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. "
2021-02-01 01:37:22 +00:00
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2021-02-01 21:43:27 +00:00
"execution_count": 3,
2021-02-01 01:37:22 +00:00
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"track object\n",
"album object\n",
"artist object\n",
"uri object\n",
"acousticness float64\n",
"danceability float64\n",
"duration_ms int64\n",
"energy float64\n",
"instrumentalness float64\n",
"key int64\n",
"liveness float64\n",
"loudness float64\n",
"mode int64\n",
"speechiness float64\n",
"tempo float64\n",
"time_signature int64\n",
"valence float64\n",
"dtype: object"
]
},
"metadata": {},
2021-02-01 21:43:27 +00:00
"execution_count": 3
2021-02-01 01:37:22 +00:00
}
],
"source": [
"scrobbles.dtypes"
]
},
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)."
],
"cell_type": "markdown",
"metadata": {}
},
2021-02-01 01:37:22 +00:00
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"tags": []
},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" acousticness danceability duration_ms energy instrumentalness \\\n",
"mean 0.170649 0.589141 2.422924e+05 0.711968 0.213591 \n",
"std 0.246679 0.173905 1.220714e+05 0.204289 0.335353 \n",
"min 0.000000 0.000000 1.578700e+04 0.000000 0.000000 \n",
"25% 0.004320 0.470000 1.893220e+05 0.586000 0.000000 \n",
"50% 0.045500 0.599000 2.264410e+05 0.749000 0.001100 \n",
"75% 0.237000 0.724000 2.787440e+05 0.878000 0.394000 \n",
"max 0.996000 0.981000 4.995315e+06 0.999000 0.995000 \n",
"\n",
" key liveness loudness mode speechiness tempo \\\n",
"mean 5.328584 0.216903 -7.127309 0.581856 0.146982 124.640429 \n",
"std 3.673929 0.173524 3.646891 0.493257 0.136440 30.809049 \n",
"min 0.000000 0.000000 -60.000000 0.000000 0.000000 0.000000 \n",
"25% 2.000000 0.099900 -8.590000 0.000000 0.047500 97.805000 \n",
"50% 6.000000 0.141000 -6.472000 1.000000 0.080800 124.992000 \n",
"75% 9.000000 0.300000 -4.827000 1.000000 0.223000 143.188000 \n",
"max 11.000000 0.995000 3.108000 1.000000 0.966000 248.028000 \n",
"\n",
" time_signature valence \n",
"mean 3.957806 0.418024 \n",
"std 0.356726 0.236941 \n",
"min 0.000000 0.000000 \n",
"25% 4.000000 0.221000 \n",
"50% 4.000000 0.398000 \n",
"75% 4.000000 0.597000 \n",
"max 5.000000 0.983000 "
],
"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 <td>0.170649</td>\n <td>0.589141</td>\n <td>2.422924e+05</td>\n <td>0.711968</td>\n <td>0.213591</td>\n <td>5.328584</td>\n <td>0.216903</td>\n <td>-7.127309</td>\n <td>0.581856</td>\n <td>0.146982</td>\n <td>124.640429</td>\n <td>3.957806</td>\n <td>0.418024</td>\n </tr>\n <tr>\n <th>std</th>\n <td>0.246679</td>\n <td>0.173905</td>\n <td>1.220714e+05</td>\n <td>0.204289</td>\n <td>0.335353</td>\n <td>3.673929</td>\n <td>0.173524</td>\n <td>3.646891</td>\n <td>0.493257</td>\n <td>0.136440</td>\n <td>30.809049</td>\n <td>0.356726</td>\n <td>0.236941</td>\n </tr>\n <tr>\n <th>min</th>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>1.578700e+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 <td>0.004320</td>\n <td>0.470000</td>\n <td>1.893220e+05</td>\n <td>0.586000</td>\n <td>0.000000</td>\n <td>2.000000</td>\n <td>0.099900</td>\n <td>-8.590000</td>\n <td>0.000000</td>\n <td>0.047500</td>\n <td>97.805000</td>\n <td>4.000000</td>\n <td>0.221000</td>\n </tr>\n <tr>\n <th>50%</th>\n <td>0.045500</td>\n <td>0.599000</td>\n <td>2.264410e+05</td>\n <td>0.749000</td>\n <td>0.001100</td>\n <td>6.000000</td>\n <td>0.141000</td>\n <td>-6.472000</td>\n <td>1.000000</td>\n <td>0.080800</td>\n <td>124.992000</td>\n <td>4.000000</td>\n <td>0.398000</td>\n </tr>\n <tr>\n <th>75%</th>\n <td>0.237000</td>\n <td>0.724000</td>\n <td>2.787440e+05</td>\n <td>0.878000</td>\n <td>0.394000</td>\n <td>9.000000</td>\n <td>0.300000</td>\n <td>-4.827000</td>\n <td>1.000000</td>\n <td>0.223000</td>\n <td>143.188000</td>\n <td>4.000000</td>\n <td>0.597000</td>\n </tr>\n <tr>\n <th>max</th>\n <td>0.996000</td>\n <td>0.981000</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 <td>0.983000</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 4
}
],
"source": [
"scrobbles.describe()[1:]"
]
},
{
"cell_type": "code",
2021-02-01 21:43:27 +00:00
"execution_count": 5,
2021-02-01 01:37:22 +00:00
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
2021-02-01 21:43:27 +00:00
" track \\\n",
"time \n",
"2020-12-31 18:35:28+00:00 Blackbird - Gorgon City Remix \n",
"2020-12-31 18:28:13+00:00 Lanterns - Dead Man's Chest Remix \n",
"2020-12-31 18:22:07+00:00 ID Check - Original Mix \n",
"2020-12-31 17:52:23+00:00 Up & Down \n",
"2020-12-31 17:00:28+00:00 Cuatro \n",
"... ... \n",
"2017-11-03 03:35:27+00:00 Julia \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:43:01+00:00 Let Go (interlude) \n",
2021-02-01 01:37:22 +00:00
"\n",
2021-02-01 21:43:27 +00:00
" album \\\n",
"time \n",
"2020-12-31 18:35:28+00:00 Blackbird EP \n",
"2020-12-31 18:28:13+00:00 Lanterns / Lanterns (Dead Man's Chest Remix) \n",
"2020-12-31 18:22:07+00:00 Toolroom Ibiza 2019 \n",
"2020-12-31 17:52:23+00:00 Emotion EP \n",
"2020-12-31 17:00:28+00:00 Tomahawk EP \n",
"... ... \n",
"2017-11-03 03:35:27+00:00 Void \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:43:01+00:00 Void \n",
2021-02-01 01:37:22 +00:00
"\n",
2021-02-01 21:43:27 +00:00
" artist \\\n",
"time \n",
"2020-12-31 18:35:28+00:00 Joeski \n",
"2020-12-31 18:28:13+00:00 Tim Reaper \n",
"2020-12-31 18:22:07+00:00 Ben A \n",
"2020-12-31 17:52:23+00:00 Purple Disco Machine \n",
"2020-12-31 17:00:28+00:00 Mystic State \n",
"... ... \n",
"2017-11-03 03:35:27+00:00 RL Grime \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:43:01+00:00 RL Grime \n",
2021-02-01 01:37:22 +00:00
"\n",
2021-02-01 21:43:27 +00:00
" uri acousticness \\\n",
"time \n",
"2020-12-31 18:35:28+00:00 spotify:track:3eGyeq8R8PscX1d13c9eJP 0.000542 \n",
"2020-12-31 18:28:13+00:00 spotify:track:3lc7wN7T29s7uRbPZR0hTH 0.001530 \n",
"2020-12-31 18:22:07+00:00 spotify:track:4x94xmQhUnd59k8oGM7AkG 0.001720 \n",
"2020-12-31 17:52:23+00:00 spotify:track:11DRarpv190YnCAXt85uFA 0.032000 \n",
"2020-12-31 17:00:28+00:00 spotify:track:6JBKvAWsMvo68a9pMa9Ujn 0.040300 \n",
"... ... ... \n",
"2017-11-03 03:35:27+00:00 spotify:track:4or82pWT9zvQNIoGckZiYb 0.003340 \n",
"2017-11-03 03:28:51+00:00 spotify:track:762ME2OHjuGo4xTbfZhpok 0.683000 \n",
"2017-11-03 02:54:37+00:00 spotify:track:2JUdMBlA5JzuemLGzZNDrf 0.683000 \n",
"2017-11-03 02:50:23+00:00 spotify:track:0jYAtTuRsRdHMuvaOXIAj5 0.034600 \n",
"2017-11-03 02:43:01+00:00 spotify:track:39FvWuHBtYQTJNdisJxZIG 0.181000 \n",
2021-02-01 01:37:22 +00:00
"\n",
2021-02-01 21:43:27 +00:00
" danceability duration_ms energy \\\n",
"time \n",
"2020-12-31 18:35:28+00:00 0.803 389834 0.857 \n",
"2020-12-31 18:28:13+00:00 0.537 440255 0.868 \n",
"2020-12-31 18:22:07+00:00 0.809 372614 0.982 \n",
"2020-12-31 17:52:23+00:00 0.758 409961 0.913 \n",
"2020-12-31 17:00:28+00:00 0.621 342866 0.680 \n",
"... ... ... ... \n",
"2017-11-03 03:35:27+00:00 0.573 301429 0.932 \n",
"2017-11-03 03:28:51+00:00 0.289 464015 0.404 \n",
"2017-11-03 02:54:37+00:00 0.593 260075 0.560 \n",
"2017-11-03 02:50:23+00:00 0.546 254815 0.850 \n",
"2017-11-03 02:43:01+00:00 0.361 153346 0.727 \n",
2021-02-01 01:37:22 +00:00
"\n",
2021-02-01 21:43:27 +00:00
" instrumentalness key liveness loudness mode \\\n",
"time \n",
"2020-12-31 18:35:28+00:00 0.840 4 0.0787 -7.273 0 \n",
"2020-12-31 18:28:13+00:00 0.877 10 0.5730 -7.319 0 \n",
"2020-12-31 18:22:07+00:00 0.911 6 0.0657 -8.690 0 \n",
"2020-12-31 17:52:23+00:00 0.739 5 0.0304 -6.712 1 \n",
"2020-12-31 17:00:28+00:00 0.803 9 0.2890 -10.943 0 \n",
"... ... ... ... ... ... \n",
"2017-11-03 03:35:27+00:00 0.744 9 0.1120 -5.158 0 \n",
"2017-11-03 03:28:51+00:00 0.854 7 0.3280 -12.815 0 \n",
"2017-11-03 02:54:37+00:00 0.109 3 0.1040 -7.059 0 \n",
"2017-11-03 02:50:23+00:00 0.680 10 0.1120 -3.366 0 \n",
"2017-11-03 02:43:01+00:00 0.710 7 0.1980 -8.480 1 \n",
2021-02-01 01:37:22 +00:00
"\n",
2021-02-01 21:43:27 +00:00
" speechiness tempo time_signature valence \n",
"time \n",
"2020-12-31 18:35:28+00:00 0.0449 125.016 4 0.2230 \n",
"2020-12-31 18:28:13+00:00 0.0618 157.015 4 0.2650 \n",
"2020-12-31 18:22:07+00:00 0.0460 123.992 4 0.8240 \n",
"2020-12-31 17:52:23+00:00 0.0518 117.997 4 0.7230 \n",
"2020-12-31 17:00:28+00:00 0.0484 139.989 4 0.2190 \n",
"... ... ... ... ... \n",
"2017-11-03 03:35:27+00:00 0.0500 168.008 4 0.1610 \n",
"2017-11-03 03:28:51+00:00 0.0352 92.873 4 0.0285 \n",
"2017-11-03 02:54:37+00:00 0.0447 113.895 4 0.3630 \n",
"2017-11-03 02:50:23+00:00 0.0386 161.996 4 0.3020 \n",
"2017-11-03 02:43:01+00:00 0.0519 104.380 4 0.0368 \n",
2021-02-01 01:37:22 +00:00
"\n",
2021-02-01 21:43:27 +00:00
"[92217 rows x 17 columns]"
2021-02-01 01:37:22 +00:00
],
2021-02-01 21:43:27 +00:00
"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 <th>2020-12-31 18:35:28+00:00</th>\n <td>Blackbird - Gorgon City Remix</td>\n <td>Blackbird EP</td>\n <td>Joeski</td>\n <td>spotify:track:3eGyeq8R8PscX1d13c9eJP</td>\n <td>0.000542</td>\n <td>0.803</td>\n <td>389834</td>\n <td>0.857</td>\n <td>0.840</td>\n <td>4</td>\n <td>0.0787</td>\n <td>-7.273</td>\n <td>0</td>\n <td>0.0449</td>\n <td>125.016</td>\n <td>4</td>\n <td>0.2230</td>\n </tr>\n <tr>\n <th>2020-12-31 18:28:13+00:00</th>\n <td>Lanterns - Dead Man's Chest Remix</td>\n <td>Lanterns / Lanterns (Dead Man's Chest Remix)</td>\n <td>Tim Reaper</td>\n <td>spotify:track:3lc7wN7T29s7uRbPZR0hTH</td>\n <td>0.001530</td>\n <td>0.537</td>\n <td>440255</td>\n <td>0.868</td>\n <td>0.877</td>\n <td>10</td>\n <td>0.5730</td>\n <td>-7.319</td>\n <td>0</td>\n <td>0.0618</td>\n <td>157.015</td>\n <td>4</td>\n <td>0.2650</td>\n </tr>\n <tr>\n <th>2020-12-31 18:22:07+00:00</th>\n <td>ID Check - Original Mix</td>\n <td>Toolroom Ibiza 2019</td>\n <td>Ben A</td>\n <td>spotify:track:4x94xmQhUnd59k8oGM7AkG</td>\n <td>0.001720</td>\n <td>0.809</td>\n <td>372614</td>\n <td>0.982</td>\n <td>0.911</td>\n <td>6</td>\n <td>0.0657</td>\n <td>-8.690</td>\n <td>0</td>\n <td>0.0460</td>\n <td>123.992</td>\n <td>4</td>\n <td>0.8240</td>\n </tr>\n <tr>\n <th>2020-12-31 17:52:23+00:00</th>\n <td>Up & Down</td>\n <td>Emotion EP</td>\n <td>Purple Disco Machine</td>\n <td>spotify:track:11DRarpv190YnCAXt85uFA</td>\n <td>0.032000</td>\n <td>0.758</td>\n <td>409961</td>\n <td>0.913</td>\n <td>0.739</td>\n <td>5</td>\n <td>0.0304</td>\n <td>-6.712</td>\n <td>1</td>\n <td>0.0518</td>\n <td>117.997</td>\n <td>4</td>\n <td>0.7230</td>\n </tr>\n <tr>\n <th>2020-12-31 17:00:28+00:00</th>\n <td>Cuatro</td>\n <td>Tomahawk EP</td>\n <td>Mystic State</td>\n <td>spotify:track:6JBKvAWsMvo68a9pMa9Ujn</td>\n <td>0.040300</td>\n <td>0.621</td>\n <td>342866</td>\n <td>0.680</td>\n <td>0.803</td>\n <td>9</td>\n <td>0.2890</td>\n <td>-10.943</td>\n <td>0</td>\n <td>0.0484</td>\n <td>139.989</td>\n <td>4</td>\n <td>0.2190</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:35
2021-02-01 01:37:22 +00:00
},
"metadata": {},
2021-02-01 21:43:27 +00:00
"execution_count": 5
2021-02-01 01:37:22 +00:00
}
],
"source": [
2021-02-01 21:43:27 +00:00
"scrobbles.sort_index(ascending=False)"
2021-02-01 01:37:22 +00:00
]
},
{
"source": [
2021-02-01 21:43:27 +00:00
"# Listening Parameters Over Time"
2021-02-01 01:37:22 +00:00
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2021-02-01 21:43:27 +00:00
"execution_count": 11,
2021-02-01 01:37:22 +00:00
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
2021-02-01 21:43:27 +00:00
"text/plain": "<Figure size 720x480 with 1 Axes>",
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\r\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n<!-- Created with matplotlib (https://matplotlib.org/) -->\r\n<svg height=\"288.512187pt\" version=\"1.1\" viewBox=\"0 0 384.828125 288.512187\" width=\"384.828125pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n <metadata>\r\n <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\r\n <cc:Work>\r\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\r\n <dc:date>2021-02-01T20:40:26.418139</dc:date>\r\n <dc:format>image/svg+xml</dc:format>\r\n <dc:creator>\r\n <cc:Agent>\r\n <dc:title>Matplotlib v3.3.4, https://matplotlib.org/</dc:title>\r\n </cc:Agent>\r\n </dc:creator>\r\n </cc:Work>\r\n </rdf:RDF>\r\n </metadata>\r\n <defs>\r\n <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\r\n </defs>\r\n <g id=\"figure_1\">\r\n <g id=\"patch_1\">\r\n <path d=\"M 0 288.512187 \r\nL 384.828125 288.512187 \r\nL 384.828125 0 \r\nL 0 0 \r\nz\r\n\" style=\"fill:none;\"/>\r\n </g>\r\n <g id=\"axes_1\">\r\n <g id=\"patch_2\">\r\n <path d=\"M 30.103125 239.758125 \r\nL 364.903125 239.758125 \r\nL 364.903125 22.318125 \r\nL 30.103125 22.318125 \r\nz\r\n\" style=\"fill:#ffffff;\"/>\r\n </g>\r\n <g id=\"matplotlib.axis_1\">\r\n <g id=\"xtick_1\">\r\n <g id=\"line2d_1\">\r\n <path clip-path=\"url(#p656d78d349)\" d=\"M 30.103125 239.758125 \r\nL 30.103125 22.318125 \r\n\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\r\n </g>\r\n <g id=\"line2d_2\">\r\n <defs>\r\n <path d=\"M 0 0 \r\nL 0 3.5 \r\n\" id=\"me5d01a8805\" style=\"stroke:#000000;stroke-width:0.8;\"/>\r\n </defs>\r\n <g>\r\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"30.103125\" xlink:href=\"#me5d01a8805\" y=\"239.758125\"/>\r\n </g>\r\n </g>\r\n </g>\r\n <g id=\"xtick_2\">\r\n <g id=\"line2d_3\">\r\n <path clip-path=\"url(#p656d78d349)\" d=\"M 48.364943 239.758125 \r\nL 48.364943 22.318125 \r\n\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\r\n </g>\r\n <g id=\"line2d_4\">\r\n <g>\r\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"48.364943\" xlink:href=\"#me5d01a8805\" y=\"239.758125\"/>\r\n </g>\r\n </g>\r\n <g id=\"text_1\">\r\n <!-- Jan -->\r\n <g transform=\"translate(40.657131 254.356562)scale(0.1 -0.1)\">\r\n <defs>\r\n <path d=\"M 9.8125 72.90625 \r\nL 19.671875 72.90625 \r\nL 19.671875 5.078125 \r\nQ 19.671875 -8.109375 14.671875 -14.0625 \r\nQ 9.671875 -20.015625 -1.421875 -20.015625 \r\nL -5.171875 -20.015625 \r\nL -5.171875 -11.71875 \r\nL -2.09375 -11.71875 \r\nQ 4.4375 -11.71875 7.125 -8.046875 \r\nQ 9.8125 -4.390625 9.8125 5.078125 \r\nz\r\n\" id=\"DejaVuSans-74\"/>\r\n <path d=\"M 34.28125 27.484375 \r\nQ 23.390625 27.484375 19.1875 25 \r\nQ 14.984375 22.515625 14.984375 16.5 \r\nQ 14.984375 11.71875 18.140625 8.90625 \r\nQ 21.296875 6.109375 26.703125 6.109375 \r\nQ 34.1875 6.109375 38.703125 11.40625 \r\nQ 43.21875 16.703125 43.21875 25.484375 \r\nL 43.21875 27.484375 \r\nz\r\nM 52.203125 31.203125 \r\nL 52.203125 0 \r\nL 43.21875 0 \r\nL 43.21875 8.296875 \r\nQ 40.140625 3.328125 35.546875 0.953125 \r\nQ 30.953125 -1.421875 24.3125 -1.421875 \r\nQ 15.921875 -1.421875 10.953125 3.296875 \r\nQ 6 8.015625 6 15.921875 \r\nQ 6 25.140625 12.171875 29.828125 \r\nQ 18.359375 34.515625 30.609375 34.515625 \r\nL 43.21875 34.515625 \r\nL 43.21875 35.40625 \r\nQ 43.21875 41.609375 39.140625 45 \r\nQ 35.0625 48.390625 27.6875 48.390625 \r\nQ 23 48.390625 18.546875 47.265625 \r\nQ 14.109375 46.140625 10.015625 43.890625 \r\nL 10.015625 52.203125 \r\nQ 14.9375 54.109375 19.578125 55.046875 \r\nQ 24.21875 56 28.609375 56 \r\nQ 40.484375 56 46.3
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoEAAAHmCAYAAAAMSlTHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAABJ0AAASdAHeZh94AAEAAElEQVR4nOydZ3gUVReA39n0CgkdQu+9Q+gdEZDeVKQpSlMRsfsp9t5FQAQBBUEQBQGRDtJr6B0CCSGUBNL73u/HTSDZmU02PST3fZ59Njlz586dsjNnzj1FE0KgUCgUCoVCoShamPJ7AAqFQqFQKBSKvEcpgQqFQqFQKBRFEKUEKhQKhUKhUBRBlBKoUCgUCoVCUQRRSqBCoVAoFApFEUQpgQqFQqFQKBRFEKUEK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SU4pYyV5dbkRqRYE1tomlYs3ZbZ5ynkw/8dIURrIcQkIcSbQqbPWJbButYsXm8CLkBPIcTDQoipQoi3kvvcZ9D+bvJ3lpXeVKQ8iBtncM0sNFg3UxY8IcRpIcRw5EO9BTKVjwn4RtO0J7O1F5k8JkKItUKIrkgrbzfgK6A+sMbK1LclKddc9/QaJSeLbp787y6LxSnHNMX69zjyRcDyWKeco68yOEddDIaQE1bW/CY7+69QKCVQ8eAghLgghJgHdEI65fdPtThl6sSaZW4v4JU8tVjQOZL83d5ygaZp7qTyCcqIZL+0Tcgp1Jcyap+c5Der1Ej+/sNgWads9BkqhNhmY597k78ftrH/JNK/ZkBG+eYJQohEIcQhIcQn3PeJG5CqSUbXuRGZPSYpY4kSQmwRQkxDTlc72thHSrT2U5q
2021-02-01 01:37:22 +00:00
},
"metadata": {
"needs_background": "light"
}
}
],
"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",
2021-02-01 01:37:22 +00:00
"plt.grid()\n",
"plt.show()"
]
},
{
"source": [
"# Imports & Setup"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2021-02-03 16:08:06 +00:00
"execution_count": 1,
2021-02-01 01:37:22 +00:00
"metadata": {},
"outputs": [],
"source": [
2021-02-01 21:43:27 +00:00
"from datetime import datetime\n",
"\n",
2021-02-01 01:37:22 +00:00
"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",
2021-02-01 01:37:22 +00:00
"\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",
2021-02-01 01:37:22 +00:00
"\n",
2021-02-01 21:43:27 +00:00
"import numpy as np\n",
2021-02-01 01:37:22 +00:00
"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)"
2021-02-01 01:37:22 +00:00
]
},
{
"source": [
"## Read Scrobble Frame"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2021-02-03 16:08:06 +00:00
"execution_count": 2,
2021-02-01 01:37:22 +00:00
"metadata": {},
"outputs": [],
"source": [
2021-02-03 16:08:06 +00:00
"scrobbles = get_query(cache=cache)"
2021-02-01 01:37:22 +00:00
]
},
{
"source": [
"## Write Scrobble Frame"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2021-02-03 16:08:06 +00:00
"execution_count": 3,
2021-02-01 01:37:22 +00:00
"metadata": {},
"outputs": [],
"source": [
2021-02-03 16:08:06 +00:00
"scrobbles.reset_index().to_csv(cache, sep='\\t')"
2021-02-01 01:37:22 +00:00
]
}
]
}