listening-analysis/analysis.ipynb

407 lines
265 KiB
Plaintext
Raw Normal View History

{
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.4-final"
},
"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",
"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."
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"track object\n",
"album object\n",
"artist object\n",
"time 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": {},
"execution_count": 14
}
],
"source": [
"scrobbles.dtypes"
]
},
{
"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",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" track \\\n",
"34017 Blackbird - Gorgon City Remix \n",
"81549 Lanterns - Dead Man's Chest Remix \n",
"46080 ID Check - Original Mix \n",
"43376 Up & Down \n",
"73918 Cuatro \n",
"... ... \n",
"74391 Julia \n",
"61000 Site Zero / The Vault \n",
"32139 Reminder (feat. How To Dress Well) \n",
"78339 Monsoon \n",
"59279 Let Go (interlude) \n",
"\n",
" album artist \\\n",
"34017 Blackbird EP Joeski \n",
"81549 Lanterns / Lanterns (Dead Man's Chest Remix) Tim Reaper \n",
"46080 Toolroom Ibiza 2019 Ben A \n",
"43376 Emotion EP Purple Disco Machine \n",
"73918 Tomahawk EP Mystic State \n",
"... ... ... \n",
"74391 Void RL Grime \n",
"61000 Void RL Grime \n",
"32139 Void RL Grime \n",
"78339 Void RL Grime \n",
"59279 Void RL Grime \n",
"\n",
" time uri \\\n",
"34017 2020-12-31 18:35:28+00:00 spotify:track:3eGyeq8R8PscX1d13c9eJP \n",
"81549 2020-12-31 18:28:13+00:00 spotify:track:3lc7wN7T29s7uRbPZR0hTH \n",
"46080 2020-12-31 18:22:07+00:00 spotify:track:4x94xmQhUnd59k8oGM7AkG \n",
"43376 2020-12-31 17:52:23+00:00 spotify:track:11DRarpv190YnCAXt85uFA \n",
"73918 2020-12-31 17:00:28+00:00 spotify:track:6JBKvAWsMvo68a9pMa9Ujn \n",
"... ... ... \n",
"74391 2017-11-03 03:35:27+00:00 spotify:track:4or82pWT9zvQNIoGckZiYb \n",
"61000 2017-11-03 03:28:51+00:00 spotify:track:762ME2OHjuGo4xTbfZhpok \n",
"32139 2017-11-03 02:54:37+00:00 spotify:track:2JUdMBlA5JzuemLGzZNDrf \n",
"78339 2017-11-03 02:50:23+00:00 spotify:track:0jYAtTuRsRdHMuvaOXIAj5 \n",
"59279 2017-11-03 02:43:01+00:00 spotify:track:39FvWuHBtYQTJNdisJxZIG \n",
"\n",
" acousticness danceability duration_ms energy instrumentalness key \\\n",
"34017 0.000542 0.803 389834 0.857 0.840 4 \n",
"81549 0.001530 0.537 440255 0.868 0.877 10 \n",
"46080 0.001720 0.809 372614 0.982 0.911 6 \n",
"43376 0.032000 0.758 409961 0.913 0.739 5 \n",
"73918 0.040300 0.621 342866 0.680 0.803 9 \n",
"... ... ... ... ... ... ... \n",
"74391 0.003340 0.573 301429 0.932 0.744 9 \n",
"61000 0.683000 0.289 464015 0.404 0.854 7 \n",
"32139 0.683000 0.593 260075 0.560 0.109 3 \n",
"78339 0.034600 0.546 254815 0.850 0.680 10 \n",
"59279 0.181000 0.361 153346 0.727 0.710 7 \n",
"\n",
" liveness loudness mode speechiness tempo time_signature valence \n",
"34017 0.0787 -7.273 0 0.0449 125.016 4 0.2230 \n",
"81549 0.5730 -7.319 0 0.0618 157.015 4 0.2650 \n",
"46080 0.0657 -8.690 0 0.0460 123.992 4 0.8240 \n",
"43376 0.0304 -6.712 1 0.0518 117.997 4 0.7230 \n",
"73918 0.2890 -10.943 0 0.0484 139.989 4 0.2190 \n",
"... ... ... ... ... ... ... ... \n",
"74391 0.1120 -5.158 0 0.0500 168.008 4 0.1610 \n",
"61000 0.3280 -12.815 0 0.0352 92.873 4 0.0285 \n",
"32139 0.1040 -7.059 0 0.0447 113.895 4 0.3630 \n",
"78339 0.1120 -3.366 0 0.0386 161.996 4 0.3020 \n",
"59279 0.1980 -8.480 1 0.0519 104.380 4 0.0368 \n",
"\n",
"[92217 rows x 18 columns]"
],
"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>time</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 </thead>\n <tbody>\n <tr>\n <th>34017</th>\n <td>Blackbird - Gorgon City Remix</td>\n <td>Blackbird EP</td>\n <td>Joeski</td>\n <td>2020-12-31 18:35:28+00:00</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>81549</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>2020-12-31 18:28:13+00:00</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>46080</th>\n <td>ID Check - Original Mix</td>\n <td>Toolroom Ibiza 2019</td>\n <td>Ben A</td>\n <td>2020-12-31 18:22:07+00:00</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>43376</th>\n <td>Up &amp; Down</td>\n <td>Emotion EP</td>\n <td>Purple Disco Machine</td>\n <td>2020-12-31 17:52:23+00:00</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>73918</th>\n <td>Cuatro</td>\n <td>Tomahawk EP</td>\n <td>Mystic State</td>\n <td>2020-12-31 17:00:28+00:00</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 <td>...</td>\n </tr>\n <tr>\n <th>74391</th>\n <td>Julia</td>\n <td>Void</td>\n <td>RL Grime</td>\n <td>2017-11-03 03:35:27+00:00</td>\n <td>spotify:track:4or82pWT9zvQNIoGckZiYb</td>\n <td>0.003340</t
},
"metadata": {},
"execution_count": 15
}
],
"source": [
"scrobbles.sort_values(by=\"time\", ascending=False)"
]
},
{
"source": [
"# Rap\n",
"\n",
"## Descriptor Stats"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"28 days spent listening since Nov. 2017\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
" acousticness danceability duration_ms energy instrumentalness \\\n",
"mean 0.179491 0.654732 217263.266814 0.711093 0.007111 \n",
"std 0.182540 0.149069 60534.505476 0.142709 0.047975 \n",
"min 0.000063 0.261000 81967.000000 0.274000 0.000000 \n",
"25% 0.039900 0.546000 180893.000000 0.604000 0.000000 \n",
"50% 0.130000 0.668000 208013.000000 0.720000 0.000000 \n",
"75% 0.253000 0.759000 245200.000000 0.821000 0.000035 \n",
"max 0.864000 0.975000 774920.000000 0.993000 0.847000 \n",
"\n",
" key liveness loudness mode speechiness tempo \\\n",
"mean 5.231103 0.243851 -6.739009 0.653965 0.275643 120.313818 \n",
"std 3.752245 0.167658 2.351719 0.475725 0.128600 31.569949 \n",
"min 0.000000 0.033300 -17.485000 0.000000 0.037800 61.113000 \n",
"25% 1.000000 0.114000 -8.324000 0.000000 0.186000 91.973000 \n",
"50% 6.000000 0.184000 -6.553000 1.000000 0.282000 120.051000 \n",
"75% 8.000000 0.339000 -5.146000 1.000000 0.362000 140.144000 \n",
"max 11.000000 0.979000 -1.354000 1.000000 0.827000 207.982000 \n",
"\n",
" time_signature valence \n",
"mean 4.008950 0.465955 \n",
"std 0.252267 0.222555 \n",
"min 1.000000 0.027200 \n",
"25% 4.000000 0.293000 \n",
"50% 4.000000 0.457000 \n",
"75% 4.000000 0.628000 \n",
"max 5.000000 0.961000 "
],
"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.179491</td>\n <td>0.654732</td>\n <td>217263.266814</td>\n <td>0.711093</td>\n <td>0.007111</td>\n <td>5.231103</td>\n <td>0.243851</td>\n <td>-6.739009</td>\n <td>0.653965</td>\n <td>0.275643</td>\n <td>120.313818</td>\n <td>4.008950</td>\n <td>0.465955</td>\n </tr>\n <tr>\n <th>std</th>\n <td>0.182540</td>\n <td>0.149069</td>\n <td>60534.505476</td>\n <td>0.142709</td>\n <td>0.047975</td>\n <td>3.752245</td>\n <td>0.167658</td>\n <td>2.351719</td>\n <td>0.475725</td>\n <td>0.128600</td>\n <td>31.569949</td>\n <td>0.252267</td>\n <td>0.222555</td>\n </tr>\n <tr>\n <th>min</th>\n <td>0.000063</td>\n <td>0.261000</td>\n <td>81967.000000</td>\n <td>0.274000</td>\n <td>0.000000</td>\n <td>0.000000</td>\n <td>0.033300</td>\n <td>-17.485000</td>\n <td>0.000000</td>\n <td>0.037800</td>\n <td>61.113000</td>\n <td>1.000000</td>\n <td>0.027200</td>\n </tr>\n <tr>\n <th>25%</th>\n <td>0.039900</td>\n <td>0.546000</td>\n <td>180893.000000</td>\n <td>0.604000</td>\n <td>0.000000</td>\n <td>1.000000</td>\n <td>0.114000</td>\n <td>-8.324000</td>\n <td>0.000000</td>\n <td>0.186000</td>\n <td>91.973000</td>\n <td>4.000000</td>\n <td>0.293000</td>\n </tr>\n <tr>\n <th>50%</th>\n <td>0.130000</td>\n <td>0.668000</td>\n <td>208013.000000</td>\n <td>0.720000</td>\n <td>0.000000</td>\n <td>6.000000</td>\n <td>0.184000</td>\n <td>-6.553000</td>\n <td>1.000000</td>\n <td>0.282000</td>\n <td>120.051000</td>\n <td>4.000000</td>\n <td>0.457000</td>\n </tr>\n <tr>\n <th>75%</th>\n <td>0.253000</td>\n <td>0.759000</td>\n <td>245200.000000</td>\n <td>0.821000</td>\n <td>0.000035</td>\n <td>8.000000</td>\n <td>0.339000</td>\n <td>-5.146000</td>\n <td>1.000000</td>\n <td>0.362000</td>\n <td>140.144000</td>\n <td>4.000000</td>\n <td>0.628000</td>\n </tr>\n <tr>\n <th>max</th>\n <td>0.864000</td>\n <td>0.975000</td>\n <td>774920.000000</td>\n <td>0.993000</td>\n <td>0.847000</td>\n <td>11.000000</td>\n <td>0.979000</td>\n <td>-1.354000</td>\n <td>1.000000</td>\n <td>0.827000</td>\n <td>207.982000</td>\n <td>5.000000</td>\n <td>0.961000</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 10
}
],
"source": [
"rap = get_playlist(\"RAP\", spotnet)\n",
"rap_frame = pd.merge(track_frame(rap.tracks), scrobbles, on=['track', 'artist']) # FILTER SCROBBLES\n",
"rap_frame = rap_frame.sort_values(by=\"time\", ascending=False) # SORT\n",
"rap_frame = rap_frame.loc[:, descriptor_headers] # DESCRIPTORS\n",
"\n",
"total_time = rap_frame[\"duration_ms\"].sum() / (1000 * 60 * 60 * 24)\n",
"print(f'{total_time:.0f} days spent listening since Nov. 2017')\n",
"\n",
"rap_frame.describe()[1:]"
]
},
{
"source": [
"# Playlist Comparisons"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"playlist_names = [\"RAP\", \"EDM\", \"ROCK\", \"METAL\", \"JAZZ\", \"POP\"]\n",
"playlists = [get_playlist(i, spotnet) for i in playlist_names]\n",
"\n",
"filtered_playlists = [pd.merge(track_frame(i.tracks), scrobbles, on=['track', 'artist']) for i in playlists]\n",
"filtered_playlists = [i.drop_duplicates(['uri']) for i in filtered_playlists]\n",
"filtered_playlists = [i.loc[:, float_headers] for i in filtered_playlists]\n",
"\n",
"playlist_mean = [i.mean() for i in filtered_playlists]\n",
"playlist_std = [i.std() for i in filtered_playlists]"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 1200x800 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=\"263.63625pt\" version=\"1.1\" viewBox=\"0 0 373.291974 263.63625\" width=\"373.291974pt\" 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-01T01:33:35.149089</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 263.63625 \r\nL 373.291974 263.63625 \r\nL 373.291974 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(#pc2143600f8)\" d=\"M 45.321307 239.758125 \r\nL 45.321307 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=\"m030abd94a1\" style=\"stroke:#000000;stroke-width:0.8;\"/>\r\n </defs>\r\n <g>\r\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"45.321307\" xlink:href=\"#m030abd94a1\" y=\"239.758125\"/>\r\n </g>\r\n </g>\r\n <g id=\"text_1\">\r\n <!-- acoust -->\r\n <g transform=\"translate(28.715057 254.356563)scale(0.1 -0.1)\">\r\n <defs>\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.34375 49.84375 \r\nQ 52.203125 43.703125 52.203125 31.203125 \r\nz\r\n\" id=\"DejaVuSans-97\"/>\r\n <path d=\"M 48.78125 52.59375 \r\nL 48.78125 44.1875 \r\nQ 44.96875 46.296875 41.140625 47.34375 \r\nQ 37.3125 48.390625 33.40625 48.390625 \r\nQ 24.65625 48.390625 19.8125 42.84375 \r\nQ 14.984375 37.3125 14.984375 27.296875 \r\nQ 14.984375 17.28125 19.8125 11.734375 \r\nQ 24.65625 6.203125 33.40625 6.203125 \r\nQ 37.3125 6.203125 41.140625 7.25 \r\nQ 44.96875 8.296875 48.78125 10.40625 \r\nL 48.78125 2.09375 \r\nQ 45.015625 0.34375 40.984375 -0.53125 \r\nQ 36.96875 -1.421875 32.421875 -1.421875 \r\nQ 20.0625 -1.421875 12.78125 6.34375 \r\nQ 5.515625 14.109375 5.515625 27.296875 \r\nQ 5.515625 40.671875 12.859375 48.328125 \r\nQ 20.21875 56 33.015625 56 \r\nQ 37.15625 56 41.109375 55.140625 \r\nQ 45.0625 54.2
"image/png": "iVBORw0KGgoAAAANSUhEUgAABA0AAALeCAYAAADBB+hWAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOzdd3hUVf7H8feZ9E4NHREURRBRBFHpimKl2LGA664Krr277lp2f6ti722tiNjoFkBRuoBSpElReg0tDVJn7u+PO5nMTSbJJJmEJHxezzMPc88995yTZBLmfuec7zGWZSEiIiIiIiIiUpTrSA9ARERERERERGomBQ1EREREREREJCAFDUREREREREQkIAUNRERERERERCQgBQ1EREREREREJCAFDUREREREREQkIAUNRERERERERCQgBQ1EREREREREJCAFDUREREREREQkIAUNRERERERERCQgBQ1EREREREREJ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/6X+jKr6NVBCG32KtFFs+Qzwnt/5l8toLwx75k1B/auKnO/kd25eJb/+eX5t/UKRm9VytDOiyPdgBWX87QvmdVRC29uBhqW0+W+/upmUHDQtV9AA6FdkHBeVUrcN9qyugrr/KqHeh0XafDeUr2899NCj7j+UCFFEpHTD/Z6Ps4osK7Asawv29M5A9f194vf8UmNMQgn1AK7zez7ZsqxA06Tv8Xt+q2VZWaW0B/A09ptLsLeILOvv/2IruGUMQbMsaxFQMAW6pB0BBmIvEwA7GeBDpbSXizNBXEDeRGF/9x7mYH+/PGVcVjCDBOD
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"x_pos = [i for i, _ in enumerate(float_headers)]\n",
"for playlist, mean, std in zip(filtered_playlists, playlist_mean, playlist_std):\n",
" plt.plot(x_pos, mean)\n",
" \n",
"plt.legend(playlist_names)\n",
"plt.xticks(x_pos, [i[:6] for i in float_headers])\n",
"plt.title('Average Playlist Descriptor')\n",
"plt.grid()\n",
"plt.show()"
]
},
{
"source": [
"# Imports & Setup"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from google.cloud import bigquery\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib as mpl\n",
"mpl.rcParams['figure.dpi'] = 200\n",
"\n",
"from analysis.net import get_spotnet, get_playlist, track_frame\n",
"from analysis.query import *\n",
"from analysis import descriptor_headers, float_headers\n",
"\n",
"import pandas as pd\n",
"\n",
"client = bigquery.Client()\n",
"spotnet = get_spotnet()\n",
"cache = 'query.csv'"
]
},
{
"source": [
"## Read Scrobble Frame"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"scrobbles = all_joined(limit=-1) # load dataset as panda frame"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"scrobbles = pd.read_csv(cache, sep='\\t', index_col=0)"
]
},
{
"source": [
"## Write Scrobble Frame"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"scrobbles.to_csv(cache, sep='\\t')"
]
}
]
}