From 458108e561dc0bb5cf38a0379bd6d01249e610c0 Mon Sep 17 00:00:00 2001 From: SilviaAlconGarrido Date: Fri, 3 Nov 2023 22:32:09 +0100 Subject: [PATCH 1/2] [workshop-spotify]SilviaAlcon --- notebooks/spotify_rest_api_challenge.ipynb | 1492 +++++++++++++++++++- 1 file changed, 1472 insertions(+), 20 deletions(-) diff --git a/notebooks/spotify_rest_api_challenge.ipynb b/notebooks/spotify_rest_api_challenge.ipynb index 5e4f8f7..6a355a4 100644 --- a/notebooks/spotify_rest_api_challenge.ipynb +++ b/notebooks/spotify_rest_api_challenge.ipynb @@ -16,13 +16,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 137, "id": "17a49776", "metadata": {}, "outputs": [], "source": [ "# Imports\n", - "\n", + "import pandas as pd \n", + "import requests\n", "\n" ] }, @@ -38,21 +39,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 138, "id": "7b5d2e52", "metadata": {}, "outputs": [], "source": [ "# Generate token with a POST request\n", "\n", - "client_id = # CLIENT ID\n", - "client_secret = # CLIENT SECRET\n", + "client_id = '7da79d3bf1aa4d29a905648ce189281c'# CLIENT ID\n", + "client_secret = 'f697728d239b4bafa24dfc57f9d5bebe'# CLIENT SECRET\n", "auth_url = 'https://accounts.spotify.com/api/token'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 139, "id": "c7901d1e", "metadata": {}, "outputs": [], @@ -64,10 +65,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 140, "id": "262e7e18", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'access_token': 'BQB_h364aOLB1KWenhG6AeH271Y_O4jE1Ma_LgzSE0ptduWOS56SsT9BEp0_Tcm0Kxe67ff4erK0EZiYqlK8RhNgtaixdzGxq6sjSFvL6ONQFT2BhLg',\n", + " 'token_type': 'Bearer',\n", + " 'expires_in': 3600}" + ] + }, + "execution_count": 140, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "access_token = auth_response['access_token']\n", "auth_response" @@ -85,17 +99,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 141, "id": "62e6d4fb", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'Authorization': 'Bearer BQB_h364aOLB1KWenhG6AeH271Y_O4jE1Ma_LgzSE0ptduWOS56SsT9BEp0_Tcm0Kxe67ff4erK0EZiYqlK8RhNgtaixdzGxq6sjSFvL6ONQFT2BhLg'}" + ] + }, + "execution_count": 141, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Base end-point construction\n", "\n", "base_url = 'https://api.spotify.com/v1/'\n", "resource = 'artists/'\n", "\n", - "header_info = {'Authorization': 'Bearer {token}'.format(token=access_token)}" + "header_info = {'Authorization': 'Bearer {token}'.format(token=access_token)}\n", + "header_info" ] }, { @@ -143,29 +169,1455 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 142, "id": "04f85940", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'https://api.spotify.com/v1/artists/4Z8W4fKeB5YxbusRsdQVPb'" + ] + }, + "execution_count": 142, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Here you can complete your endpoint URI\n", - "\n", - "full_endpoint = \n", + "artist_id = '4Z8W4fKeB5YxbusRsdQVPb'\n", + "method = 'artists/'\n", + "full_endpoint = base_url + method + artist_id\n", "full_endpoint" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 143, "id": "50ec3959", "metadata": {}, "outputs": [], "source": [ "# Start building your playlist!!!\n", + "response = requests.get(full_endpoint, headers=header_info).json()" + ] + }, + { + "cell_type": "code", + "execution_count": 144, + "id": "af6a65f7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Z8W4fKeB5YxbusRsdQVPb'},\n", + " 'followers': {'href': None, 'total': 8879323},\n", + " 'genres': ['alternative rock',\n", + " 'art rock',\n", + " 'melancholia',\n", + " 'oxford indie',\n", + " 'permanent wave',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/4Z8W4fKeB5YxbusRsdQVPb',\n", + " 'id': '4Z8W4fKeB5YxbusRsdQVPb',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eba03696716c9ee605006047fd',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174a03696716c9ee605006047fd',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178a03696716c9ee605006047fd',\n", + " 'width': 160}],\n", + " 'name': 'Radiohead',\n", + " 'popularity': 78,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:4Z8W4fKeB5YxbusRsdQVPb'}" + ] + }, + "execution_count": 144, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response" + ] + }, + { + "cell_type": "code", + "execution_count": 145, + "id": "e130c42f", + "metadata": {}, + "outputs": [], + "source": [ + "dict_artist = dict((key, [response[key]])for key in ['id', 'name', 'genres', 'popularity', 'followers']if key in response)" + ] + }, + { + "cell_type": "code", + "execution_count": 146, + "id": "5bb6a406", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': ['4Z8W4fKeB5YxbusRsdQVPb'],\n", + " 'name': ['Radiohead'],\n", + " 'genres': [['alternative rock',\n", + " 'art rock',\n", + " 'melancholia',\n", + " 'oxford indie',\n", + " 'permanent wave',\n", + " 'rock']],\n", + " 'popularity': [78],\n", + " 'followers': [{'href': None, 'total': 8879323}]}" + ] + }, + "execution_count": 146, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dict_artist" + ] + }, + { + "cell_type": "code", + "execution_count": 147, + "id": "940039fa", + "metadata": {}, + "outputs": [], + "source": [ + "df_artist = pd.DataFrame(dict_artist)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 148, + "id": "816670c1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamegenrespopularityfollowers
04Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8879323}
\n", + "
" + ], + "text/plain": [ + " id name \\\n", + "0 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "\n", + " genres popularity \\\n", + "0 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "\n", + " followers \n", + "0 {'href': None, 'total': 8879323} " + ] + }, + "execution_count": 148, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_artist" + ] + }, + { + "cell_type": "code", + "execution_count": 173, + "id": "0753d02f", + "metadata": {}, + "outputs": [], + "source": [ + "df_artist = df_artist.rename(columns={'id': 'related_id',\n", + " 'name': 'related_name',\n", + " 'genres': 'related_genres',\n", + " 'popularity': 'related_popularity',\n", + " 'followers': 'related_followers'\n", + " })" + ] + }, + { + "cell_type": "code", + "execution_count": 174, + "id": "bcd01ef0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
related_idrelated_namerelated_genresrelated_popularityrelated_followers
04Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8879323}
\n", + "
" + ], + "text/plain": [ + " related_id related_name \\\n", + "0 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "\n", + " related_genres related_popularity \\\n", + "0 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "\n", + " related_followers \n", + "0 {'href': None, 'total': 8879323} " + ] + }, + "execution_count": 174, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_artist" + ] + }, + { + "cell_type": "markdown", + "id": "12958f21", + "metadata": {}, + "source": [ + "# Let's get the related artists info" + ] + }, + { + "cell_type": "code", + "execution_count": 149, + "id": "6e77944a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'https://api.spotify.com/v1/artists/4Z8W4fKeB5YxbusRsdQVPb/related-artists'" + ] + }, + "execution_count": 149, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "parameters = '/related-artists'\n", + "artist_id = '4Z8W4fKeB5YxbusRsdQVPb'\n", "\n", - "\n" + "url = base_url + resource + artist_id + parameters\n", + "\n", + "url" + ] + }, + { + "cell_type": "code", + "execution_count": 150, + "id": "ed0ba73e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4CvTDPKA6W06DRfBnZKrau'},\n", + " 'followers': {'href': None, 'total': 984762},\n", + " 'genres': ['alternative rock',\n", + " 'art pop',\n", + " 'art rock',\n", + " 'electronica',\n", + " 'glitch pop',\n", + " 'indie rock',\n", + " 'oxford indie'],\n", + " 'href': 'https://api.spotify.com/v1/artists/4CvTDPKA6W06DRfBnZKrau',\n", + " 'id': '4CvTDPKA6W06DRfBnZKrau',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb3153f6fe26063cfcbfc57677',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051743153f6fe26063cfcbfc57677',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1783153f6fe26063cfcbfc57677',\n", + " 'width': 160}],\n", + " 'name': 'Thom Yorke',\n", + " 'popularity': 54,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:4CvTDPKA6W06DRfBnZKrau'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6zvul52xwTWzilBZl6BUbT'},\n", + " 'followers': {'href': None, 'total': 2692738},\n", + " 'genres': ['alternative rock', 'boston rock', 'permanent wave', 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6zvul52xwTWzilBZl6BUbT',\n", + " 'id': '6zvul52xwTWzilBZl6BUbT',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebd0456128dd330d18e18b4715',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174d0456128dd330d18e18b4715',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178d0456128dd330d18e18b4715',\n", + " 'width': 160}],\n", + " 'name': 'Pixies',\n", + " 'popularity': 68,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6zvul52xwTWzilBZl6BUbT'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7MhMgCo0Bl0Kukl93PZbYS'},\n", + " 'followers': {'href': None, 'total': 3098682},\n", + " 'genres': ['alternative rock',\n", + " 'britpop',\n", + " 'madchester',\n", + " 'permanent wave',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/7MhMgCo0Bl0Kukl93PZbYS',\n", + " 'id': '7MhMgCo0Bl0Kukl93PZbYS',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb00620d736644d2359ce99430',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000517400620d736644d2359ce99430',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f17800620d736644d2359ce99430',\n", + " 'width': 160}],\n", + " 'name': 'Blur',\n", + " 'popularity': 67,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7MhMgCo0Bl0Kukl93PZbYS'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3yY2gUcIsjMr8hjo51PoJ8'},\n", + " 'followers': {'href': None, 'total': 4642841},\n", + " 'genres': ['madchester',\n", + " 'new wave',\n", + " 'permanent wave',\n", + " 'rock',\n", + " 'uk post-punk'],\n", + " 'href': 'https://api.spotify.com/v1/artists/3yY2gUcIsjMr8hjo51PoJ8',\n", + " 'id': '3yY2gUcIsjMr8hjo51PoJ8',\n", + " 'images': [{'height': 1516,\n", + " 'url': 'https://i.scdn.co/image/481b980af463122013e4578c08fb8c5cbfaed1e9',\n", + " 'width': 1000},\n", + " {'height': 970,\n", + " 'url': 'https://i.scdn.co/image/4bf08a9e6eea088b20d4092d1322bbd3f39ff9af',\n", + " 'width': 640},\n", + " {'height': 303,\n", + " 'url': 'https://i.scdn.co/image/bd4c7f5ff2c5c4385604e60c71eac1dd498ddbd9',\n", + " 'width': 200},\n", + " {'height': 97,\n", + " 'url': 'https://i.scdn.co/image/d3a2542f2811b5b01ee3483ec7c193f72a882ea1',\n", + " 'width': 64}],\n", + " 'name': 'The Smiths',\n", + " 'popularity': 74,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:3yY2gUcIsjMr8hjo51PoJ8'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6liAMWkVf5LH7YR9yfFy1Y'},\n", + " 'followers': {'href': None, 'total': 1850836},\n", + " 'genres': ['alternative rock',\n", + " 'art pop',\n", + " 'dark pop',\n", + " 'electronica',\n", + " 'laboratorio',\n", + " 'trip hop'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6liAMWkVf5LH7YR9yfFy1Y',\n", + " 'id': '6liAMWkVf5LH7YR9yfFy1Y',\n", + " 'images': [{'height': 680,\n", + " 'url': 'https://i.scdn.co/image/05d3721739aee511a898081ab140daa7890a0120',\n", + " 'width': 1000},\n", + " {'height': 435,\n", + " 'url': 'https://i.scdn.co/image/27802710b01453435de93d71bab2c9988a841ace',\n", + " 'width': 640},\n", + " {'height': 136,\n", + " 'url': 'https://i.scdn.co/image/333ac38e3c8ab5fcdc238cc46535a4abb802eccc',\n", + " 'width': 200},\n", + " {'height': 44,\n", + " 'url': 'https://i.scdn.co/image/10052054c06626f6a900e687b20886e462f75568',\n", + " 'width': 64}],\n", + " 'name': 'Portishead',\n", + " 'popularity': 59,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6liAMWkVf5LH7YR9yfFy1Y'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/432R46LaYsJZV2Gmc4jUV5'},\n", + " 'followers': {'href': None, 'total': 2247194},\n", + " 'genres': ['alternative rock',\n", + " 'indie rock',\n", + " 'madchester',\n", + " 'new wave',\n", + " 'post-punk',\n", + " 'punk',\n", + " 'rock',\n", + " 'uk post-punk'],\n", + " 'href': 'https://api.spotify.com/v1/artists/432R46LaYsJZV2Gmc4jUV5',\n", + " 'id': '432R46LaYsJZV2Gmc4jUV5',\n", + " 'images': [{'height': 658,\n", + " 'url': 'https://i.scdn.co/image/5eeddd733170399db794d2c430a8d2cde7ae1425',\n", + " 'width': 1000},\n", + " {'height': 421,\n", + " 'url': 'https://i.scdn.co/image/d3c6bcb07a5ecddf86e791fa901bf3792fe6e6c7',\n", + " 'width': 640},\n", + " {'height': 132,\n", + " 'url': 'https://i.scdn.co/image/d384ebd3d3fda0ad219fed6b9014a59e65fbb385',\n", + " 'width': 200},\n", + " {'height': 42,\n", + " 'url': 'https://i.scdn.co/image/1b5195d5e9b5aac07fb0c801deb1926138222036',\n", + " 'width': 64}],\n", + " 'name': 'Joy Division',\n", + " 'popularity': 61,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:432R46LaYsJZV2Gmc4jUV5'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7bu3H8JO7d0UbMoVzbo70s'},\n", + " 'followers': {'href': None, 'total': 4883404},\n", + " 'genres': ['new wave', 'permanent wave', 'rock', 'uk post-punk'],\n", + " 'href': 'https://api.spotify.com/v1/artists/7bu3H8JO7d0UbMoVzbo70s',\n", + " 'id': '7bu3H8JO7d0UbMoVzbo70s',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/7ca743e822b80133971ccf5c70fcbd77a4f4f508',\n", + " 'width': 640},\n", + " {'height': 200,\n", + " 'url': 'https://i.scdn.co/image/2cb2e14783685fd3d27006891aaaa35fc53cd82d',\n", + " 'width': 200},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/9e1ed6613ac0ef103fbfca3c11ff35fec8d9c6b1',\n", + " 'width': 64}],\n", + " 'name': 'The Cure',\n", + " 'popularity': 73,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7bu3H8JO7d0UbMoVzbo70s'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/0epOFNiUfyON9EYx7Tpr6V'},\n", + " 'followers': {'href': None, 'total': 5258866},\n", + " 'genres': ['alternative rock',\n", + " 'garage rock',\n", + " 'modern rock',\n", + " 'permanent wave',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/0epOFNiUfyON9EYx7Tpr6V',\n", + " 'id': '0epOFNiUfyON9EYx7Tpr6V',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebcaea403b29f6a09260b6a18a',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174caea403b29f6a09260b6a18a',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178caea403b29f6a09260b6a18a',\n", + " 'width': 160}],\n", + " 'name': 'The Strokes',\n", + " 'popularity': 73,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0epOFNiUfyON9EYx7Tpr6V'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/40Yq4vzPs9VNUrIBG5Jr2i'},\n", + " 'followers': {'href': None, 'total': 4760553},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'grunge',\n", + " 'permanent wave',\n", + " 'rock',\n", + " 'spacegrunge'],\n", + " 'href': 'https://api.spotify.com/v1/artists/40Yq4vzPs9VNUrIBG5Jr2i',\n", + " 'id': '40Yq4vzPs9VNUrIBG5Jr2i',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebbd85f631779e65b01349d747',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174bd85f631779e65b01349d747',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178bd85f631779e65b01349d747',\n", + " 'width': 160}],\n", + " 'name': 'The Smashing Pumpkins',\n", + " 'popularity': 70,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:40Yq4vzPs9VNUrIBG5Jr2i'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5UqTO8smerMvxHYA5xsXb6'},\n", + " 'followers': {'href': None, 'total': 1072268},\n", + " 'genres': ['alternative rock',\n", + " 'indie rock',\n", + " 'noise pop',\n", + " 'noise rock',\n", + " 'rock',\n", + " 'shoegaze'],\n", + " 'href': 'https://api.spotify.com/v1/artists/5UqTO8smerMvxHYA5xsXb6',\n", + " 'id': '5UqTO8smerMvxHYA5xsXb6',\n", + " 'images': [{'height': 987,\n", + " 'url': 'https://i.scdn.co/image/af335c11a73e9311516bb28800be58311410d1be',\n", + " 'width': 1000},\n", + " {'height': 632,\n", + " 'url': 'https://i.scdn.co/image/a6f14050fe0b0e188d23298efffd3ff06511e99c',\n", + " 'width': 640},\n", + " {'height': 197,\n", + " 'url': 'https://i.scdn.co/image/976d63d12b1c9ea37edbef69ad5439ab79a59889',\n", + " 'width': 200},\n", + " {'height': 63,\n", + " 'url': 'https://i.scdn.co/image/4efa809bcbed4385812febceb5fe665f6dde361e',\n", + " 'width': 64}],\n", + " 'name': 'Sonic Youth',\n", + " 'popularity': 55,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:5UqTO8smerMvxHYA5xsXb6'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3G3Gdm0ZRAOxLrbyjfhii5'},\n", + " 'followers': {'href': None, 'total': 810926},\n", + " 'genres': ['alternative rock', 'dream pop', 'noise pop', 'shoegaze'],\n", + " 'href': 'https://api.spotify.com/v1/artists/3G3Gdm0ZRAOxLrbyjfhii5',\n", + " 'id': '3G3Gdm0ZRAOxLrbyjfhii5',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb21c79e4e6e1af6af9b94d3a0',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000517421c79e4e6e1af6af9b94d3a0',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f17821c79e4e6e1af6af9b94d3a0',\n", + " 'width': 160}],\n", + " 'name': 'my bloody valentine',\n", + " 'popularity': 55,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:3G3Gdm0ZRAOxLrbyjfhii5'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/72X6FHxaShda0XeQw3vbeF'},\n", + " 'followers': {'href': None, 'total': 856978},\n", + " 'genres': ['alternative rock',\n", + " 'dream pop',\n", + " 'nu gaze',\n", + " 'reading indie',\n", + " 'shoegaze'],\n", + " 'href': 'https://api.spotify.com/v1/artists/72X6FHxaShda0XeQw3vbeF',\n", + " 'id': '72X6FHxaShda0XeQw3vbeF',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb653481f50df3c11791d6132a',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174653481f50df3c11791d6132a',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178653481f50df3c11791d6132a',\n", + " 'width': 160}],\n", + " 'name': 'Slowdive',\n", + " 'popularity': 60,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:72X6FHxaShda0XeQw3vbeF'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7w29UYBi0qsHi5RTcv3lmA'},\n", + " 'followers': {'href': None, 'total': 1916375},\n", + " 'genres': ['alternative rock',\n", + " 'art pop',\n", + " 'electronica',\n", + " 'experimental pop',\n", + " 'experimental vocal',\n", + " 'icelandic experimental',\n", + " 'icelandic pop',\n", + " 'icelandic singer-songwriter',\n", + " 'metropopolis',\n", + " 'permanent wave',\n", + " 'trip hop'],\n", + " 'href': 'https://api.spotify.com/v1/artists/7w29UYBi0qsHi5RTcv3lmA',\n", + " 'id': '7w29UYBi0qsHi5RTcv3lmA',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebaeb5c04fdd8ec6273850d207',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174aeb5c04fdd8ec6273850d207',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178aeb5c04fdd8ec6273850d207',\n", + " 'width': 160}],\n", + " 'name': 'Björk',\n", + " 'popularity': 59,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7w29UYBi0qsHi5RTcv3lmA'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3nnQpaTvKb5jCQabZefACI'},\n", + " 'followers': {'href': None, 'total': 1154600},\n", + " 'genres': ['melancholia', 'permanent wave', 'singer-songwriter'],\n", + " 'href': 'https://api.spotify.com/v1/artists/3nnQpaTvKb5jCQabZefACI',\n", + " 'id': '3nnQpaTvKb5jCQabZefACI',\n", + " 'images': [{'height': 1520,\n", + " 'url': 'https://i.scdn.co/image/67779606c7f151618a28f62b1d24fb514d39dacf',\n", + " 'width': 1000},\n", + " {'height': 973,\n", + " 'url': 'https://i.scdn.co/image/248e8ddbf1be229fd0c31722fb0a01b31b01f474',\n", + " 'width': 640},\n", + " {'height': 304,\n", + " 'url': 'https://i.scdn.co/image/8822f816dea6ea25c70e942763c9812c6271e516',\n", + " 'width': 200},\n", + " {'height': 97,\n", + " 'url': 'https://i.scdn.co/image/2a93d455e8981b0e1f6f1918b934c454c1243b20',\n", + " 'width': 64}],\n", + " 'name': 'Jeff Buckley',\n", + " 'popularity': 61,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:3nnQpaTvKb5jCQabZefACI'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3WaJSfKnzc65VDgmj2zU8B'},\n", + " 'followers': {'href': None, 'total': 1615840},\n", + " 'genres': ['alternative dance',\n", + " 'alternative rock',\n", + " 'indie rock',\n", + " 'indietronica',\n", + " 'modern rock',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/3WaJSfKnzc65VDgmj2zU8B',\n", + " 'id': '3WaJSfKnzc65VDgmj2zU8B',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebc31f8e7aad462874455cf070',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174c31f8e7aad462874455cf070',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178c31f8e7aad462874455cf070',\n", + " 'width': 160}],\n", + " 'name': 'Interpol',\n", + " 'popularity': 61,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:3WaJSfKnzc65VDgmj2zU8B'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6Ghvu1VvMGScGpOUJBAHNH'},\n", + " 'followers': {'href': None, 'total': 4540047},\n", + " 'genres': ['alternative metal',\n", + " 'nu metal',\n", + " 'rap metal',\n", + " 'rock',\n", + " 'sacramento indie'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6Ghvu1VvMGScGpOUJBAHNH',\n", + " 'id': '6Ghvu1VvMGScGpOUJBAHNH',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb4b2da0b72cab26ac518f1f0d',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051744b2da0b72cab26ac518f1f0d',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1784b2da0b72cab26ac518f1f0d',\n", + " 'width': 160}],\n", + " 'name': 'Deftones',\n", + " 'popularity': 75,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6Ghvu1VvMGScGpOUJBAHNH'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3kjuyTCjPG1WMFCiyc5IuB'},\n", + " 'followers': {'href': None, 'total': 2233201},\n", + " 'genres': ['alternative rock',\n", + " 'baroque pop',\n", + " 'canadian indie',\n", + " 'chamber pop',\n", + " 'indie rock',\n", + " 'indietronica',\n", + " 'modern rock',\n", + " 'permanent wave',\n", + " 'quebec indie',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/3kjuyTCjPG1WMFCiyc5IuB',\n", + " 'id': '3kjuyTCjPG1WMFCiyc5IuB',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eba044e15eee771205956dcbf8',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174a044e15eee771205956dcbf8',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178a044e15eee771205956dcbf8',\n", + " 'width': 160}],\n", + " 'name': 'Arcade Fire',\n", + " 'popularity': 62,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:3kjuyTCjPG1WMFCiyc5IuB'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/1nJvji2KIlWSseXRSlNYsC'},\n", + " 'followers': {'href': None, 'total': 1799299},\n", + " 'genres': ['alternative rock',\n", + " 'melancholia',\n", + " 'permanent wave',\n", + " 'protopunk',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/1nJvji2KIlWSseXRSlNYsC',\n", + " 'id': '1nJvji2KIlWSseXRSlNYsC',\n", + " 'images': [{'height': 1236,\n", + " 'url': 'https://i.scdn.co/image/d69c2cf10323bf08443c7d122f3a1824a760ab57',\n", + " 'width': 1000},\n", + " {'height': 791,\n", + " 'url': 'https://i.scdn.co/image/24e7531935f88f55744cc8c9ed2528f466cba276',\n", + " 'width': 640},\n", + " {'height': 247,\n", + " 'url': 'https://i.scdn.co/image/fedcb6f64de6571e2c208a21fc16b9e05e38cf2f',\n", + " 'width': 200},\n", + " {'height': 79,\n", + " 'url': 'https://i.scdn.co/image/0fda1f46337398e35d5c7c672ddc77beb68a8f93',\n", + " 'width': 64}],\n", + " 'name': 'The Velvet Underground',\n", + " 'popularity': 60,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:1nJvji2KIlWSseXRSlNYsC'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6FXMGgJwohJLUSr5nVlf9X'},\n", + " 'followers': {'href': None, 'total': 2076307},\n", + " 'genres': ['downtempo', 'electronica', 'trip hop'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6FXMGgJwohJLUSr5nVlf9X',\n", + " 'id': '6FXMGgJwohJLUSr5nVlf9X',\n", + " 'images': [{'height': 1335,\n", + " 'url': 'https://i.scdn.co/image/c8bbeedb05f38ae5cb982a7daf4bf7129cca892c',\n", + " 'width': 1000},\n", + " {'height': 855,\n", + " 'url': 'https://i.scdn.co/image/52c2a824e84f4e8adf0b12418f9f8306b4b5b77a',\n", + " 'width': 640},\n", + " {'height': 267,\n", + " 'url': 'https://i.scdn.co/image/0d6b7677f8291c5158bdace8a6e027880c527c2a',\n", + " 'width': 200},\n", + " {'height': 85,\n", + " 'url': 'https://i.scdn.co/image/c055290bb6e97a589d8ca659cd452a8e9831c2c4',\n", + " 'width': 64}],\n", + " 'name': 'Massive Attack',\n", + " 'popularity': 61,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6FXMGgJwohJLUSr5nVlf9X'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2ApaG60P4r0yhBoDCGD8YG'},\n", + " 'followers': {'href': None, 'total': 1000064},\n", + " 'genres': ['alternative rock',\n", + " 'indie rock',\n", + " 'melancholia',\n", + " 'singer-songwriter'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2ApaG60P4r0yhBoDCGD8YG',\n", + " 'id': '2ApaG60P4r0yhBoDCGD8YG',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb079739b801ab3f105866b76f',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174079739b801ab3f105866b76f',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178079739b801ab3f105866b76f',\n", + " 'width': 160}],\n", + " 'name': 'Elliott Smith',\n", + " 'popularity': 62,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2ApaG60P4r0yhBoDCGD8YG'}]}" + ] + }, + "execution_count": 150, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = requests.get(url, headers=header_info).json()\n", + "response" ] }, + { + "cell_type": "code", + "execution_count": 151, + "id": "3e74fa81", + "metadata": {}, + "outputs": [], + "source": [ + "df_related_artists = pd.DataFrame(response['artists'])[['id', 'name', 'genres', 'popularity','followers']]" + ] + }, + { + "cell_type": "code", + "execution_count": 152, + "id": "c36ae1c6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamegenrespopularityfollowers
04CvTDPKA6W06DRfBnZKrauThom Yorke[alternative rock, art pop, art rock, electron...54{'href': None, 'total': 984762}
16zvul52xwTWzilBZl6BUbTPixies[alternative rock, boston rock, permanent wave...68{'href': None, 'total': 2692738}
27MhMgCo0Bl0Kukl93PZbYSBlur[alternative rock, britpop, madchester, perman...67{'href': None, 'total': 3098682}
33yY2gUcIsjMr8hjo51PoJ8The Smiths[madchester, new wave, permanent wave, rock, u...74{'href': None, 'total': 4642841}
46liAMWkVf5LH7YR9yfFy1YPortishead[alternative rock, art pop, dark pop, electron...59{'href': None, 'total': 1850836}
5432R46LaYsJZV2Gmc4jUV5Joy Division[alternative rock, indie rock, madchester, new...61{'href': None, 'total': 2247194}
67bu3H8JO7d0UbMoVzbo70sThe Cure[new wave, permanent wave, rock, uk post-punk]73{'href': None, 'total': 4883404}
70epOFNiUfyON9EYx7Tpr6VThe Strokes[alternative rock, garage rock, modern rock, p...73{'href': None, 'total': 5258866}
840Yq4vzPs9VNUrIBG5Jr2iThe Smashing Pumpkins[alternative metal, alternative rock, grunge, ...70{'href': None, 'total': 4760553}
95UqTO8smerMvxHYA5xsXb6Sonic Youth[alternative rock, indie rock, noise pop, nois...55{'href': None, 'total': 1072268}
103G3Gdm0ZRAOxLrbyjfhii5my bloody valentine[alternative rock, dream pop, noise pop, shoeg...55{'href': None, 'total': 810926}
1172X6FHxaShda0XeQw3vbeFSlowdive[alternative rock, dream pop, nu gaze, reading...60{'href': None, 'total': 856978}
127w29UYBi0qsHi5RTcv3lmABjörk[alternative rock, art pop, electronica, exper...59{'href': None, 'total': 1916375}
133nnQpaTvKb5jCQabZefACIJeff Buckley[melancholia, permanent wave, singer-songwriter]61{'href': None, 'total': 1154600}
143WaJSfKnzc65VDgmj2zU8BInterpol[alternative dance, alternative rock, indie ro...61{'href': None, 'total': 1615840}
156Ghvu1VvMGScGpOUJBAHNHDeftones[alternative metal, nu metal, rap metal, rock,...75{'href': None, 'total': 4540047}
163kjuyTCjPG1WMFCiyc5IuBArcade Fire[alternative rock, baroque pop, canadian indie...62{'href': None, 'total': 2233201}
171nJvji2KIlWSseXRSlNYsCThe Velvet Underground[alternative rock, melancholia, permanent wave...60{'href': None, 'total': 1799299}
186FXMGgJwohJLUSr5nVlf9XMassive Attack[downtempo, electronica, trip hop]61{'href': None, 'total': 2076307}
192ApaG60P4r0yhBoDCGD8YGElliott Smith[alternative rock, indie rock, melancholia, si...62{'href': None, 'total': 1000064}
\n", + "
" + ], + "text/plain": [ + " id name \\\n", + "0 4CvTDPKA6W06DRfBnZKrau Thom Yorke \n", + "1 6zvul52xwTWzilBZl6BUbT Pixies \n", + "2 7MhMgCo0Bl0Kukl93PZbYS Blur \n", + "3 3yY2gUcIsjMr8hjo51PoJ8 The Smiths \n", + "4 6liAMWkVf5LH7YR9yfFy1Y Portishead \n", + "5 432R46LaYsJZV2Gmc4jUV5 Joy Division \n", + "6 7bu3H8JO7d0UbMoVzbo70s The Cure \n", + "7 0epOFNiUfyON9EYx7Tpr6V The Strokes \n", + "8 40Yq4vzPs9VNUrIBG5Jr2i The Smashing Pumpkins \n", + "9 5UqTO8smerMvxHYA5xsXb6 Sonic Youth \n", + "10 3G3Gdm0ZRAOxLrbyjfhii5 my bloody valentine \n", + "11 72X6FHxaShda0XeQw3vbeF Slowdive \n", + "12 7w29UYBi0qsHi5RTcv3lmA Björk \n", + "13 3nnQpaTvKb5jCQabZefACI Jeff Buckley \n", + "14 3WaJSfKnzc65VDgmj2zU8B Interpol \n", + "15 6Ghvu1VvMGScGpOUJBAHNH Deftones \n", + "16 3kjuyTCjPG1WMFCiyc5IuB Arcade Fire \n", + "17 1nJvji2KIlWSseXRSlNYsC The Velvet Underground \n", + "18 6FXMGgJwohJLUSr5nVlf9X Massive Attack \n", + "19 2ApaG60P4r0yhBoDCGD8YG Elliott Smith \n", + "\n", + " genres popularity \\\n", + "0 [alternative rock, art pop, art rock, electron... 54 \n", + "1 [alternative rock, boston rock, permanent wave... 68 \n", + "2 [alternative rock, britpop, madchester, perman... 67 \n", + "3 [madchester, new wave, permanent wave, rock, u... 74 \n", + "4 [alternative rock, art pop, dark pop, electron... 59 \n", + "5 [alternative rock, indie rock, madchester, new... 61 \n", + "6 [new wave, permanent wave, rock, uk post-punk] 73 \n", + "7 [alternative rock, garage rock, modern rock, p... 73 \n", + "8 [alternative metal, alternative rock, grunge, ... 70 \n", + "9 [alternative rock, indie rock, noise pop, nois... 55 \n", + "10 [alternative rock, dream pop, noise pop, shoeg... 55 \n", + "11 [alternative rock, dream pop, nu gaze, reading... 60 \n", + "12 [alternative rock, art pop, electronica, exper... 59 \n", + "13 [melancholia, permanent wave, singer-songwriter] 61 \n", + "14 [alternative dance, alternative rock, indie ro... 61 \n", + "15 [alternative metal, nu metal, rap metal, rock,... 75 \n", + "16 [alternative rock, baroque pop, canadian indie... 62 \n", + "17 [alternative rock, melancholia, permanent wave... 60 \n", + "18 [downtempo, electronica, trip hop] 61 \n", + "19 [alternative rock, indie rock, melancholia, si... 62 \n", + "\n", + " followers \n", + "0 {'href': None, 'total': 984762} \n", + "1 {'href': None, 'total': 2692738} \n", + "2 {'href': None, 'total': 3098682} \n", + "3 {'href': None, 'total': 4642841} \n", + "4 {'href': None, 'total': 1850836} \n", + "5 {'href': None, 'total': 2247194} \n", + "6 {'href': None, 'total': 4883404} \n", + "7 {'href': None, 'total': 5258866} \n", + "8 {'href': None, 'total': 4760553} \n", + "9 {'href': None, 'total': 1072268} \n", + "10 {'href': None, 'total': 810926} \n", + "11 {'href': None, 'total': 856978} \n", + "12 {'href': None, 'total': 1916375} \n", + "13 {'href': None, 'total': 1154600} \n", + "14 {'href': None, 'total': 1615840} \n", + "15 {'href': None, 'total': 4540047} \n", + "16 {'href': None, 'total': 2233201} \n", + "17 {'href': None, 'total': 1799299} \n", + "18 {'href': None, 'total': 2076307} \n", + "19 {'href': None, 'total': 1000064} " + ] + }, + "execution_count": 152, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_related_artists" + ] + }, + { + "cell_type": "code", + "execution_count": 162, + "id": "91761b44", + "metadata": {}, + "outputs": [], + "source": [ + "#rename de columns\n", + "df_related_artists = df_related_artists.rename(columns={'id': 'related_id',\n", + " 'name': 'related_name',\n", + " 'genres': 'related_genres',\n", + " 'popularity': 'related_popularity',\n", + " 'followers': 'related_followers'\n", + " })" + ] + }, + { + "cell_type": "code", + "execution_count": 163, + "id": "60bf353f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
related_idrelated_namerelated_genresrelated_popularityrelated_followers
04CvTDPKA6W06DRfBnZKrauThom Yorke[alternative rock, art pop, art rock, electron...54{'href': None, 'total': 984762}
16zvul52xwTWzilBZl6BUbTPixies[alternative rock, boston rock, permanent wave...68{'href': None, 'total': 2692738}
27MhMgCo0Bl0Kukl93PZbYSBlur[alternative rock, britpop, madchester, perman...67{'href': None, 'total': 3098682}
33yY2gUcIsjMr8hjo51PoJ8The Smiths[madchester, new wave, permanent wave, rock, u...74{'href': None, 'total': 4642841}
46liAMWkVf5LH7YR9yfFy1YPortishead[alternative rock, art pop, dark pop, electron...59{'href': None, 'total': 1850836}
5432R46LaYsJZV2Gmc4jUV5Joy Division[alternative rock, indie rock, madchester, new...61{'href': None, 'total': 2247194}
67bu3H8JO7d0UbMoVzbo70sThe Cure[new wave, permanent wave, rock, uk post-punk]73{'href': None, 'total': 4883404}
70epOFNiUfyON9EYx7Tpr6VThe Strokes[alternative rock, garage rock, modern rock, p...73{'href': None, 'total': 5258866}
840Yq4vzPs9VNUrIBG5Jr2iThe Smashing Pumpkins[alternative metal, alternative rock, grunge, ...70{'href': None, 'total': 4760553}
95UqTO8smerMvxHYA5xsXb6Sonic Youth[alternative rock, indie rock, noise pop, nois...55{'href': None, 'total': 1072268}
103G3Gdm0ZRAOxLrbyjfhii5my bloody valentine[alternative rock, dream pop, noise pop, shoeg...55{'href': None, 'total': 810926}
1172X6FHxaShda0XeQw3vbeFSlowdive[alternative rock, dream pop, nu gaze, reading...60{'href': None, 'total': 856978}
127w29UYBi0qsHi5RTcv3lmABjörk[alternative rock, art pop, electronica, exper...59{'href': None, 'total': 1916375}
133nnQpaTvKb5jCQabZefACIJeff Buckley[melancholia, permanent wave, singer-songwriter]61{'href': None, 'total': 1154600}
143WaJSfKnzc65VDgmj2zU8BInterpol[alternative dance, alternative rock, indie ro...61{'href': None, 'total': 1615840}
156Ghvu1VvMGScGpOUJBAHNHDeftones[alternative metal, nu metal, rap metal, rock,...75{'href': None, 'total': 4540047}
163kjuyTCjPG1WMFCiyc5IuBArcade Fire[alternative rock, baroque pop, canadian indie...62{'href': None, 'total': 2233201}
171nJvji2KIlWSseXRSlNYsCThe Velvet Underground[alternative rock, melancholia, permanent wave...60{'href': None, 'total': 1799299}
186FXMGgJwohJLUSr5nVlf9XMassive Attack[downtempo, electronica, trip hop]61{'href': None, 'total': 2076307}
192ApaG60P4r0yhBoDCGD8YGElliott Smith[alternative rock, indie rock, melancholia, si...62{'href': None, 'total': 1000064}
\n", + "
" + ], + "text/plain": [ + " related_id related_name \\\n", + "0 4CvTDPKA6W06DRfBnZKrau Thom Yorke \n", + "1 6zvul52xwTWzilBZl6BUbT Pixies \n", + "2 7MhMgCo0Bl0Kukl93PZbYS Blur \n", + "3 3yY2gUcIsjMr8hjo51PoJ8 The Smiths \n", + "4 6liAMWkVf5LH7YR9yfFy1Y Portishead \n", + "5 432R46LaYsJZV2Gmc4jUV5 Joy Division \n", + "6 7bu3H8JO7d0UbMoVzbo70s The Cure \n", + "7 0epOFNiUfyON9EYx7Tpr6V The Strokes \n", + "8 40Yq4vzPs9VNUrIBG5Jr2i The Smashing Pumpkins \n", + "9 5UqTO8smerMvxHYA5xsXb6 Sonic Youth \n", + "10 3G3Gdm0ZRAOxLrbyjfhii5 my bloody valentine \n", + "11 72X6FHxaShda0XeQw3vbeF Slowdive \n", + "12 7w29UYBi0qsHi5RTcv3lmA Björk \n", + "13 3nnQpaTvKb5jCQabZefACI Jeff Buckley \n", + "14 3WaJSfKnzc65VDgmj2zU8B Interpol \n", + "15 6Ghvu1VvMGScGpOUJBAHNH Deftones \n", + "16 3kjuyTCjPG1WMFCiyc5IuB Arcade Fire \n", + "17 1nJvji2KIlWSseXRSlNYsC The Velvet Underground \n", + "18 6FXMGgJwohJLUSr5nVlf9X Massive Attack \n", + "19 2ApaG60P4r0yhBoDCGD8YG Elliott Smith \n", + "\n", + " related_genres related_popularity \\\n", + "0 [alternative rock, art pop, art rock, electron... 54 \n", + "1 [alternative rock, boston rock, permanent wave... 68 \n", + "2 [alternative rock, britpop, madchester, perman... 67 \n", + "3 [madchester, new wave, permanent wave, rock, u... 74 \n", + "4 [alternative rock, art pop, dark pop, electron... 59 \n", + "5 [alternative rock, indie rock, madchester, new... 61 \n", + "6 [new wave, permanent wave, rock, uk post-punk] 73 \n", + "7 [alternative rock, garage rock, modern rock, p... 73 \n", + "8 [alternative metal, alternative rock, grunge, ... 70 \n", + "9 [alternative rock, indie rock, noise pop, nois... 55 \n", + "10 [alternative rock, dream pop, noise pop, shoeg... 55 \n", + "11 [alternative rock, dream pop, nu gaze, reading... 60 \n", + "12 [alternative rock, art pop, electronica, exper... 59 \n", + "13 [melancholia, permanent wave, singer-songwriter] 61 \n", + "14 [alternative dance, alternative rock, indie ro... 61 \n", + "15 [alternative metal, nu metal, rap metal, rock,... 75 \n", + "16 [alternative rock, baroque pop, canadian indie... 62 \n", + "17 [alternative rock, melancholia, permanent wave... 60 \n", + "18 [downtempo, electronica, trip hop] 61 \n", + "19 [alternative rock, indie rock, melancholia, si... 62 \n", + "\n", + " related_followers \n", + "0 {'href': None, 'total': 984762} \n", + "1 {'href': None, 'total': 2692738} \n", + "2 {'href': None, 'total': 3098682} \n", + "3 {'href': None, 'total': 4642841} \n", + "4 {'href': None, 'total': 1850836} \n", + "5 {'href': None, 'total': 2247194} \n", + "6 {'href': None, 'total': 4883404} \n", + "7 {'href': None, 'total': 5258866} \n", + "8 {'href': None, 'total': 4760553} \n", + "9 {'href': None, 'total': 1072268} \n", + "10 {'href': None, 'total': 810926} \n", + "11 {'href': None, 'total': 856978} \n", + "12 {'href': None, 'total': 1916375} \n", + "13 {'href': None, 'total': 1154600} \n", + "14 {'href': None, 'total': 1615840} \n", + "15 {'href': None, 'total': 4540047} \n", + "16 {'href': None, 'total': 2233201} \n", + "17 {'href': None, 'total': 1799299} \n", + "18 {'href': None, 'total': 2076307} \n", + "19 {'href': None, 'total': 1000064} " + ] + }, + "execution_count": 163, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_related_artists" + ] + }, + { + "cell_type": "code", + "execution_count": 168, + "id": "1c283965", + "metadata": {}, + "outputs": [], + "source": [ + "#add a column with selected id artist\n", + "df_related_artists['artist_id'] = artist_id" + ] + }, + { + "cell_type": "code", + "execution_count": 175, + "id": "ca482942", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
related_idrelated_name_xrelated_genres_xrelated_popularity_xrelated_followers_xartist_idrelated_name_yrelated_genres_yrelated_popularity_yrelated_followers_y
\n", + "
" + ], + "text/plain": [ + "Empty DataFrame\n", + "Columns: [related_id, related_name_x, related_genres_x, related_popularity_x, related_followers_x, artist_id, related_name_y, related_genres_y, related_popularity_y, related_followers_y]\n", + "Index: []" + ] + }, + "execution_count": 175, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#join artist and related artist to merge info\n", + "df_related_artists = pd.merge(df_related_artists, df_artist, on='related_id')\n", + "df_related_artists" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9213fd43", + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "id": "98827be6", @@ -221,9 +1673,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python [conda env:.conda-ironhack]", + "display_name": "Python (m1_env)", "language": "python", - "name": "conda-env-.conda-ironhack-py" + "name": "m1_env" }, "language_info": { "codemirror_mode": { @@ -235,7 +1687,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.11" + "version": "3.10.13" } }, "nbformat": 4, From d9a9e1cad3afd9c21aa92ce7b0ea4d5695c3ba81 Mon Sep 17 00:00:00 2001 From: SilviaAlconGarrido Date: Sat, 4 Nov 2023 21:58:25 +0100 Subject: [PATCH 2/2] finish --- notebooks/spotify_rest_api_challenge.ipynb | 1250 ++++++++++++++++---- 1 file changed, 1024 insertions(+), 226 deletions(-) diff --git a/notebooks/spotify_rest_api_challenge.ipynb b/notebooks/spotify_rest_api_challenge.ipynb index 6a355a4..8779f2c 100644 --- a/notebooks/spotify_rest_api_challenge.ipynb +++ b/notebooks/spotify_rest_api_challenge.ipynb @@ -16,15 +16,14 @@ }, { "cell_type": "code", - "execution_count": 137, + "execution_count": 72, "id": "17a49776", "metadata": {}, "outputs": [], "source": [ "# Imports\n", "import pandas as pd \n", - "import requests\n", - "\n" + "import requests" ] }, { @@ -39,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": 138, + "execution_count": 73, "id": "7b5d2e52", "metadata": {}, "outputs": [], @@ -53,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 139, + "execution_count": 74, "id": "c7901d1e", "metadata": {}, "outputs": [], @@ -65,19 +64,19 @@ }, { "cell_type": "code", - "execution_count": 140, + "execution_count": 75, "id": "262e7e18", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'access_token': 'BQB_h364aOLB1KWenhG6AeH271Y_O4jE1Ma_LgzSE0ptduWOS56SsT9BEp0_Tcm0Kxe67ff4erK0EZiYqlK8RhNgtaixdzGxq6sjSFvL6ONQFT2BhLg',\n", + "{'access_token': 'BQD-S1YtHAzDtNCyWqexzkl-Bjf7w1b6kXUffz-TBFP2Llwg1GzQO4TIugvF2eJSCmnrpyOtVd1n7FOsmPM-nzB5oTWRv8fFNBWOqJl-IHG_nqYI6Lc',\n", " 'token_type': 'Bearer',\n", " 'expires_in': 3600}" ] }, - "execution_count": 140, + "execution_count": 75, "metadata": {}, "output_type": "execute_result" } @@ -99,17 +98,17 @@ }, { "cell_type": "code", - "execution_count": 141, + "execution_count": 76, "id": "62e6d4fb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'Authorization': 'Bearer BQB_h364aOLB1KWenhG6AeH271Y_O4jE1Ma_LgzSE0ptduWOS56SsT9BEp0_Tcm0Kxe67ff4erK0EZiYqlK8RhNgtaixdzGxq6sjSFvL6ONQFT2BhLg'}" + "{'Authorization': 'Bearer BQD-S1YtHAzDtNCyWqexzkl-Bjf7w1b6kXUffz-TBFP2Llwg1GzQO4TIugvF2eJSCmnrpyOtVd1n7FOsmPM-nzB5oTWRv8fFNBWOqJl-IHG_nqYI6Lc'}" ] }, - "execution_count": 141, + "execution_count": 76, "metadata": {}, "output_type": "execute_result" } @@ -169,7 +168,7 @@ }, { "cell_type": "code", - "execution_count": 142, + "execution_count": 77, "id": "04f85940", "metadata": {}, "outputs": [ @@ -179,7 +178,7 @@ "'https://api.spotify.com/v1/artists/4Z8W4fKeB5YxbusRsdQVPb'" ] }, - "execution_count": 142, + "execution_count": 77, "metadata": {}, "output_type": "execute_result" } @@ -194,7 +193,7 @@ }, { "cell_type": "code", - "execution_count": 143, + "execution_count": 78, "id": "50ec3959", "metadata": {}, "outputs": [], @@ -205,7 +204,7 @@ }, { "cell_type": "code", - "execution_count": 144, + "execution_count": 79, "id": "af6a65f7", "metadata": {}, "outputs": [ @@ -213,7 +212,7 @@ "data": { "text/plain": [ "{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Z8W4fKeB5YxbusRsdQVPb'},\n", - " 'followers': {'href': None, 'total': 8879323},\n", + " 'followers': {'href': None, 'total': 8884416},\n", " 'genres': ['alternative rock',\n", " 'art rock',\n", " 'melancholia',\n", @@ -237,7 +236,7 @@ " 'uri': 'spotify:artist:4Z8W4fKeB5YxbusRsdQVPb'}" ] }, - "execution_count": 144, + "execution_count": 79, "metadata": {}, "output_type": "execute_result" } @@ -248,7 +247,7 @@ }, { "cell_type": "code", - "execution_count": 145, + "execution_count": 80, "id": "e130c42f", "metadata": {}, "outputs": [], @@ -258,7 +257,7 @@ }, { "cell_type": "code", - "execution_count": 146, + "execution_count": 81, "id": "5bb6a406", "metadata": {}, "outputs": [ @@ -274,10 +273,10 @@ " 'permanent wave',\n", " 'rock']],\n", " 'popularity': [78],\n", - " 'followers': [{'href': None, 'total': 8879323}]}" + " 'followers': [{'href': None, 'total': 8884416}]}" ] }, - "execution_count": 146, + "execution_count": 81, "metadata": {}, "output_type": "execute_result" } @@ -288,7 +287,7 @@ }, { "cell_type": "code", - "execution_count": 147, + "execution_count": 82, "id": "940039fa", "metadata": {}, "outputs": [], @@ -298,7 +297,7 @@ }, { "cell_type": "code", - "execution_count": 148, + "execution_count": 83, "id": "816670c1", "metadata": {}, "outputs": [ @@ -337,7 +336,7 @@ " Radiohead\n", " [alternative rock, art rock, melancholia, oxfo...\n", " 78\n", - " {'href': None, 'total': 8879323}\n", + " {'href': None, 'total': 8884416}\n", " \n", " \n", "\n", @@ -351,10 +350,10 @@ "0 [alternative rock, art rock, melancholia, oxfo... 78 \n", "\n", " followers \n", - "0 {'href': None, 'total': 8879323} " + "0 {'href': None, 'total': 8884416} " ] }, - "execution_count": 148, + "execution_count": 83, "metadata": {}, "output_type": "execute_result" } @@ -365,22 +364,18 @@ }, { "cell_type": "code", - "execution_count": 173, + "execution_count": 84, "id": "0753d02f", "metadata": {}, "outputs": [], "source": [ - "df_artist = df_artist.rename(columns={'id': 'related_id',\n", - " 'name': 'related_name',\n", - " 'genres': 'related_genres',\n", - " 'popularity': 'related_popularity',\n", - " 'followers': 'related_followers'\n", + "df_artist = df_artist.rename(columns={'id': 'artist_id',\n", " })" ] }, { "cell_type": "code", - "execution_count": 174, + "execution_count": 85, "id": "bcd01ef0", "metadata": {}, "outputs": [ @@ -405,11 +400,11 @@ " \n", " \n", " \n", - " related_id\n", - " related_name\n", - " related_genres\n", - " related_popularity\n", - " related_followers\n", + " artist_id\n", + " name\n", + " genres\n", + " popularity\n", + " followers\n", " \n", " \n", " \n", @@ -419,24 +414,24 @@ " Radiohead\n", " [alternative rock, art rock, melancholia, oxfo...\n", " 78\n", - " {'href': None, 'total': 8879323}\n", + " {'href': None, 'total': 8884416}\n", " \n", " \n", "\n", "" ], "text/plain": [ - " related_id related_name \\\n", - "0 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + " artist_id name \\\n", + "0 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", "\n", - " related_genres related_popularity \\\n", - "0 [alternative rock, art rock, melancholia, oxfo... 78 \n", + " genres popularity \\\n", + "0 [alternative rock, art rock, melancholia, oxfo... 78 \n", "\n", - " related_followers \n", - "0 {'href': None, 'total': 8879323} " + " followers \n", + "0 {'href': None, 'total': 8884416} " ] }, - "execution_count": 174, + "execution_count": 85, "metadata": {}, "output_type": "execute_result" } @@ -455,7 +450,7 @@ }, { "cell_type": "code", - "execution_count": 149, + "execution_count": 86, "id": "6e77944a", "metadata": {}, "outputs": [ @@ -465,7 +460,7 @@ "'https://api.spotify.com/v1/artists/4Z8W4fKeB5YxbusRsdQVPb/related-artists'" ] }, - "execution_count": 149, + "execution_count": 86, "metadata": {}, "output_type": "execute_result" } @@ -481,7 +476,7 @@ }, { "cell_type": "code", - "execution_count": 150, + "execution_count": 87, "id": "ed0ba73e", "metadata": {}, "outputs": [ @@ -489,7 +484,7 @@ "data": { "text/plain": [ "{'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4CvTDPKA6W06DRfBnZKrau'},\n", - " 'followers': {'href': None, 'total': 984762},\n", + " 'followers': {'href': None, 'total': 985116},\n", " 'genres': ['alternative rock',\n", " 'art pop',\n", " 'art rock',\n", @@ -513,7 +508,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:4CvTDPKA6W06DRfBnZKrau'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6zvul52xwTWzilBZl6BUbT'},\n", - " 'followers': {'href': None, 'total': 2692738},\n", + " 'followers': {'href': None, 'total': 2694003},\n", " 'genres': ['alternative rock', 'boston rock', 'permanent wave', 'rock'],\n", " 'href': 'https://api.spotify.com/v1/artists/6zvul52xwTWzilBZl6BUbT',\n", " 'id': '6zvul52xwTWzilBZl6BUbT',\n", @@ -531,7 +526,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:6zvul52xwTWzilBZl6BUbT'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7MhMgCo0Bl0Kukl93PZbYS'},\n", - " 'followers': {'href': None, 'total': 3098682},\n", + " 'followers': {'href': None, 'total': 3099793},\n", " 'genres': ['alternative rock',\n", " 'britpop',\n", " 'madchester',\n", @@ -553,7 +548,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:7MhMgCo0Bl0Kukl93PZbYS'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3yY2gUcIsjMr8hjo51PoJ8'},\n", - " 'followers': {'href': None, 'total': 4642841},\n", + " 'followers': {'href': None, 'total': 4647089},\n", " 'genres': ['madchester',\n", " 'new wave',\n", " 'permanent wave',\n", @@ -578,7 +573,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:3yY2gUcIsjMr8hjo51PoJ8'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6liAMWkVf5LH7YR9yfFy1Y'},\n", - " 'followers': {'href': None, 'total': 1850836},\n", + " 'followers': {'href': None, 'total': 1851714},\n", " 'genres': ['alternative rock',\n", " 'art pop',\n", " 'dark pop',\n", @@ -604,8 +599,9 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:6liAMWkVf5LH7YR9yfFy1Y'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/432R46LaYsJZV2Gmc4jUV5'},\n", - " 'followers': {'href': None, 'total': 2247194},\n", + " 'followers': {'href': None, 'total': 2248108},\n", " 'genres': ['alternative rock',\n", + " 'art rock',\n", " 'indie rock',\n", " 'madchester',\n", " 'new wave',\n", @@ -632,7 +628,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:432R46LaYsJZV2Gmc4jUV5'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7bu3H8JO7d0UbMoVzbo70s'},\n", - " 'followers': {'href': None, 'total': 4883404},\n", + " 'followers': {'href': None, 'total': 4886284},\n", " 'genres': ['new wave', 'permanent wave', 'rock', 'uk post-punk'],\n", " 'href': 'https://api.spotify.com/v1/artists/7bu3H8JO7d0UbMoVzbo70s',\n", " 'id': '7bu3H8JO7d0UbMoVzbo70s',\n", @@ -650,7 +646,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:7bu3H8JO7d0UbMoVzbo70s'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/0epOFNiUfyON9EYx7Tpr6V'},\n", - " 'followers': {'href': None, 'total': 5258866},\n", + " 'followers': {'href': None, 'total': 5260718},\n", " 'genres': ['alternative rock',\n", " 'garage rock',\n", " 'modern rock',\n", @@ -672,7 +668,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:0epOFNiUfyON9EYx7Tpr6V'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/40Yq4vzPs9VNUrIBG5Jr2i'},\n", - " 'followers': {'href': None, 'total': 4760553},\n", + " 'followers': {'href': None, 'total': 4762503},\n", " 'genres': ['alternative metal',\n", " 'alternative rock',\n", " 'grunge',\n", @@ -695,7 +691,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:40Yq4vzPs9VNUrIBG5Jr2i'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5UqTO8smerMvxHYA5xsXb6'},\n", - " 'followers': {'href': None, 'total': 1072268},\n", + " 'followers': {'href': None, 'total': 1072692},\n", " 'genres': ['alternative rock',\n", " 'indie rock',\n", " 'noise pop',\n", @@ -721,7 +717,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:5UqTO8smerMvxHYA5xsXb6'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3G3Gdm0ZRAOxLrbyjfhii5'},\n", - " 'followers': {'href': None, 'total': 810926},\n", + " 'followers': {'href': None, 'total': 811456},\n", " 'genres': ['alternative rock', 'dream pop', 'noise pop', 'shoegaze'],\n", " 'href': 'https://api.spotify.com/v1/artists/3G3Gdm0ZRAOxLrbyjfhii5',\n", " 'id': '3G3Gdm0ZRAOxLrbyjfhii5',\n", @@ -735,11 +731,11 @@ " 'url': 'https://i.scdn.co/image/ab6761610000f17821c79e4e6e1af6af9b94d3a0',\n", " 'width': 160}],\n", " 'name': 'my bloody valentine',\n", - " 'popularity': 55,\n", + " 'popularity': 54,\n", " 'type': 'artist',\n", " 'uri': 'spotify:artist:3G3Gdm0ZRAOxLrbyjfhii5'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/72X6FHxaShda0XeQw3vbeF'},\n", - " 'followers': {'href': None, 'total': 856978},\n", + " 'followers': {'href': None, 'total': 857825},\n", " 'genres': ['alternative rock',\n", " 'dream pop',\n", " 'nu gaze',\n", @@ -761,7 +757,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:72X6FHxaShda0XeQw3vbeF'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7w29UYBi0qsHi5RTcv3lmA'},\n", - " 'followers': {'href': None, 'total': 1916375},\n", + " 'followers': {'href': None, 'total': 1917156},\n", " 'genres': ['alternative rock',\n", " 'art pop',\n", " 'electronica',\n", @@ -789,7 +785,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:7w29UYBi0qsHi5RTcv3lmA'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3nnQpaTvKb5jCQabZefACI'},\n", - " 'followers': {'href': None, 'total': 1154600},\n", + " 'followers': {'href': None, 'total': 1155378},\n", " 'genres': ['melancholia', 'permanent wave', 'singer-songwriter'],\n", " 'href': 'https://api.spotify.com/v1/artists/3nnQpaTvKb5jCQabZefACI',\n", " 'id': '3nnQpaTvKb5jCQabZefACI',\n", @@ -810,7 +806,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:3nnQpaTvKb5jCQabZefACI'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3WaJSfKnzc65VDgmj2zU8B'},\n", - " 'followers': {'href': None, 'total': 1615840},\n", + " 'followers': {'href': None, 'total': 1616230},\n", " 'genres': ['alternative dance',\n", " 'alternative rock',\n", " 'indie rock',\n", @@ -833,7 +829,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:3WaJSfKnzc65VDgmj2zU8B'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6Ghvu1VvMGScGpOUJBAHNH'},\n", - " 'followers': {'href': None, 'total': 4540047},\n", + " 'followers': {'href': None, 'total': 4543728},\n", " 'genres': ['alternative metal',\n", " 'nu metal',\n", " 'rap metal',\n", @@ -855,7 +851,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:6Ghvu1VvMGScGpOUJBAHNH'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3kjuyTCjPG1WMFCiyc5IuB'},\n", - " 'followers': {'href': None, 'total': 2233201},\n", + " 'followers': {'href': None, 'total': 2233533},\n", " 'genres': ['alternative rock',\n", " 'baroque pop',\n", " 'canadian indie',\n", @@ -882,7 +878,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:3kjuyTCjPG1WMFCiyc5IuB'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/1nJvji2KIlWSseXRSlNYsC'},\n", - " 'followers': {'href': None, 'total': 1799299},\n", + " 'followers': {'href': None, 'total': 1800640},\n", " 'genres': ['alternative rock',\n", " 'melancholia',\n", " 'permanent wave',\n", @@ -907,7 +903,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:1nJvji2KIlWSseXRSlNYsC'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6FXMGgJwohJLUSr5nVlf9X'},\n", - " 'followers': {'href': None, 'total': 2076307},\n", + " 'followers': {'href': None, 'total': 2076951},\n", " 'genres': ['downtempo', 'electronica', 'trip hop'],\n", " 'href': 'https://api.spotify.com/v1/artists/6FXMGgJwohJLUSr5nVlf9X',\n", " 'id': '6FXMGgJwohJLUSr5nVlf9X',\n", @@ -928,7 +924,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:6FXMGgJwohJLUSr5nVlf9X'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2ApaG60P4r0yhBoDCGD8YG'},\n", - " 'followers': {'href': None, 'total': 1000064},\n", + " 'followers': {'href': None, 'total': 1000573},\n", " 'genres': ['alternative rock',\n", " 'indie rock',\n", " 'melancholia',\n", @@ -950,7 +946,7 @@ " 'uri': 'spotify:artist:2ApaG60P4r0yhBoDCGD8YG'}]}" ] }, - "execution_count": 150, + "execution_count": 87, "metadata": {}, "output_type": "execute_result" } @@ -962,7 +958,7 @@ }, { "cell_type": "code", - "execution_count": 151, + "execution_count": 88, "id": "3e74fa81", "metadata": {}, "outputs": [], @@ -972,8 +968,8 @@ }, { "cell_type": "code", - "execution_count": 152, - "id": "c36ae1c6", + "execution_count": 89, + "id": "9213fd43", "metadata": {}, "outputs": [ { @@ -1011,7 +1007,7 @@ " Thom Yorke\n", " [alternative rock, art pop, art rock, electron...\n", " 54\n", - " {'href': None, 'total': 984762}\n", + " {'href': None, 'total': 985116}\n", " \n", " \n", " 1\n", @@ -1019,7 +1015,7 @@ " Pixies\n", " [alternative rock, boston rock, permanent wave...\n", " 68\n", - " {'href': None, 'total': 2692738}\n", + " {'href': None, 'total': 2694003}\n", " \n", " \n", " 2\n", @@ -1027,7 +1023,7 @@ " Blur\n", " [alternative rock, britpop, madchester, perman...\n", " 67\n", - " {'href': None, 'total': 3098682}\n", + " {'href': None, 'total': 3099793}\n", " \n", " \n", " 3\n", @@ -1035,7 +1031,7 @@ " The Smiths\n", " [madchester, new wave, permanent wave, rock, u...\n", " 74\n", - " {'href': None, 'total': 4642841}\n", + " {'href': None, 'total': 4647089}\n", " \n", " \n", " 4\n", @@ -1043,15 +1039,15 @@ " Portishead\n", " [alternative rock, art pop, dark pop, electron...\n", " 59\n", - " {'href': None, 'total': 1850836}\n", + " {'href': None, 'total': 1851714}\n", " \n", " \n", " 5\n", " 432R46LaYsJZV2Gmc4jUV5\n", " Joy Division\n", - " [alternative rock, indie rock, madchester, new...\n", + " [alternative rock, art rock, indie rock, madch...\n", " 61\n", - " {'href': None, 'total': 2247194}\n", + " {'href': None, 'total': 2248108}\n", " \n", " \n", " 6\n", @@ -1059,7 +1055,7 @@ " The Cure\n", " [new wave, permanent wave, rock, uk post-punk]\n", " 73\n", - " {'href': None, 'total': 4883404}\n", + " {'href': None, 'total': 4886284}\n", " \n", " \n", " 7\n", @@ -1067,7 +1063,7 @@ " The Strokes\n", " [alternative rock, garage rock, modern rock, p...\n", " 73\n", - " {'href': None, 'total': 5258866}\n", + " {'href': None, 'total': 5260718}\n", " \n", " \n", " 8\n", @@ -1075,7 +1071,7 @@ " The Smashing Pumpkins\n", " [alternative metal, alternative rock, grunge, ...\n", " 70\n", - " {'href': None, 'total': 4760553}\n", + " {'href': None, 'total': 4762503}\n", " \n", " \n", " 9\n", @@ -1083,15 +1079,15 @@ " Sonic Youth\n", " [alternative rock, indie rock, noise pop, nois...\n", " 55\n", - " {'href': None, 'total': 1072268}\n", + " {'href': None, 'total': 1072692}\n", " \n", " \n", " 10\n", " 3G3Gdm0ZRAOxLrbyjfhii5\n", " my bloody valentine\n", " [alternative rock, dream pop, noise pop, shoeg...\n", - " 55\n", - " {'href': None, 'total': 810926}\n", + " 54\n", + " {'href': None, 'total': 811456}\n", " \n", " \n", " 11\n", @@ -1099,7 +1095,7 @@ " Slowdive\n", " [alternative rock, dream pop, nu gaze, reading...\n", " 60\n", - " {'href': None, 'total': 856978}\n", + " {'href': None, 'total': 857825}\n", " \n", " \n", " 12\n", @@ -1107,7 +1103,7 @@ " Björk\n", " [alternative rock, art pop, electronica, exper...\n", " 59\n", - " {'href': None, 'total': 1916375}\n", + " {'href': None, 'total': 1917156}\n", " \n", " \n", " 13\n", @@ -1115,7 +1111,7 @@ " Jeff Buckley\n", " [melancholia, permanent wave, singer-songwriter]\n", " 61\n", - " {'href': None, 'total': 1154600}\n", + " {'href': None, 'total': 1155378}\n", " \n", " \n", " 14\n", @@ -1123,7 +1119,7 @@ " Interpol\n", " [alternative dance, alternative rock, indie ro...\n", " 61\n", - " {'href': None, 'total': 1615840}\n", + " {'href': None, 'total': 1616230}\n", " \n", " \n", " 15\n", @@ -1131,7 +1127,7 @@ " Deftones\n", " [alternative metal, nu metal, rap metal, rock,...\n", " 75\n", - " {'href': None, 'total': 4540047}\n", + " {'href': None, 'total': 4543728}\n", " \n", " \n", " 16\n", @@ -1139,7 +1135,7 @@ " Arcade Fire\n", " [alternative rock, baroque pop, canadian indie...\n", " 62\n", - " {'href': None, 'total': 2233201}\n", + " {'href': None, 'total': 2233533}\n", " \n", " \n", " 17\n", @@ -1147,7 +1143,7 @@ " The Velvet Underground\n", " [alternative rock, melancholia, permanent wave...\n", " 60\n", - " {'href': None, 'total': 1799299}\n", + " {'href': None, 'total': 1800640}\n", " \n", " \n", " 18\n", @@ -1155,7 +1151,7 @@ " Massive Attack\n", " [downtempo, electronica, trip hop]\n", " 61\n", - " {'href': None, 'total': 2076307}\n", + " {'href': None, 'total': 2076951}\n", " \n", " \n", " 19\n", @@ -1163,7 +1159,7 @@ " Elliott Smith\n", " [alternative rock, indie rock, melancholia, si...\n", " 62\n", - " {'href': None, 'total': 1000064}\n", + " {'href': None, 'total': 1000573}\n", " \n", " \n", "\n", @@ -1198,12 +1194,12 @@ "2 [alternative rock, britpop, madchester, perman... 67 \n", "3 [madchester, new wave, permanent wave, rock, u... 74 \n", "4 [alternative rock, art pop, dark pop, electron... 59 \n", - "5 [alternative rock, indie rock, madchester, new... 61 \n", + "5 [alternative rock, art rock, indie rock, madch... 61 \n", "6 [new wave, permanent wave, rock, uk post-punk] 73 \n", "7 [alternative rock, garage rock, modern rock, p... 73 \n", "8 [alternative metal, alternative rock, grunge, ... 70 \n", "9 [alternative rock, indie rock, noise pop, nois... 55 \n", - "10 [alternative rock, dream pop, noise pop, shoeg... 55 \n", + "10 [alternative rock, dream pop, noise pop, shoeg... 54 \n", "11 [alternative rock, dream pop, nu gaze, reading... 60 \n", "12 [alternative rock, art pop, electronica, exper... 59 \n", "13 [melancholia, permanent wave, singer-songwriter] 61 \n", @@ -1215,29 +1211,29 @@ "19 [alternative rock, indie rock, melancholia, si... 62 \n", "\n", " followers \n", - "0 {'href': None, 'total': 984762} \n", - "1 {'href': None, 'total': 2692738} \n", - "2 {'href': None, 'total': 3098682} \n", - "3 {'href': None, 'total': 4642841} \n", - "4 {'href': None, 'total': 1850836} \n", - "5 {'href': None, 'total': 2247194} \n", - "6 {'href': None, 'total': 4883404} \n", - "7 {'href': None, 'total': 5258866} \n", - "8 {'href': None, 'total': 4760553} \n", - "9 {'href': None, 'total': 1072268} \n", - "10 {'href': None, 'total': 810926} \n", - "11 {'href': None, 'total': 856978} \n", - "12 {'href': None, 'total': 1916375} \n", - "13 {'href': None, 'total': 1154600} \n", - "14 {'href': None, 'total': 1615840} \n", - "15 {'href': None, 'total': 4540047} \n", - "16 {'href': None, 'total': 2233201} \n", - "17 {'href': None, 'total': 1799299} \n", - "18 {'href': None, 'total': 2076307} \n", - "19 {'href': None, 'total': 1000064} " + "0 {'href': None, 'total': 985116} \n", + "1 {'href': None, 'total': 2694003} \n", + "2 {'href': None, 'total': 3099793} \n", + "3 {'href': None, 'total': 4647089} \n", + "4 {'href': None, 'total': 1851714} \n", + "5 {'href': None, 'total': 2248108} \n", + "6 {'href': None, 'total': 4886284} \n", + "7 {'href': None, 'total': 5260718} \n", + "8 {'href': None, 'total': 4762503} \n", + "9 {'href': None, 'total': 1072692} \n", + "10 {'href': None, 'total': 811456} \n", + "11 {'href': None, 'total': 857825} \n", + "12 {'href': None, 'total': 1917156} \n", + "13 {'href': None, 'total': 1155378} \n", + "14 {'href': None, 'total': 1616230} \n", + "15 {'href': None, 'total': 4543728} \n", + "16 {'href': None, 'total': 2233533} \n", + "17 {'href': None, 'total': 1800640} \n", + "18 {'href': None, 'total': 2076951} \n", + "19 {'href': None, 'total': 1000573} " ] }, - "execution_count": 152, + "execution_count": 89, "metadata": {}, "output_type": "execute_result" } @@ -1248,24 +1244,8 @@ }, { "cell_type": "code", - "execution_count": 162, - "id": "91761b44", - "metadata": {}, - "outputs": [], - "source": [ - "#rename de columns\n", - "df_related_artists = df_related_artists.rename(columns={'id': 'related_id',\n", - " 'name': 'related_name',\n", - " 'genres': 'related_genres',\n", - " 'popularity': 'related_popularity',\n", - " 'followers': 'related_followers'\n", - " })" - ] - }, - { - "cell_type": "code", - "execution_count": 163, - "id": "60bf353f", + "execution_count": 90, + "id": "e6a32e52", "metadata": {}, "outputs": [ { @@ -1303,7 +1283,7 @@ " Thom Yorke\n", " [alternative rock, art pop, art rock, electron...\n", " 54\n", - " {'href': None, 'total': 984762}\n", + " {'href': None, 'total': 985116}\n", " \n", " \n", " 1\n", @@ -1311,7 +1291,7 @@ " Pixies\n", " [alternative rock, boston rock, permanent wave...\n", " 68\n", - " {'href': None, 'total': 2692738}\n", + " {'href': None, 'total': 2694003}\n", " \n", " \n", " 2\n", @@ -1319,7 +1299,7 @@ " Blur\n", " [alternative rock, britpop, madchester, perman...\n", " 67\n", - " {'href': None, 'total': 3098682}\n", + " {'href': None, 'total': 3099793}\n", " \n", " \n", " 3\n", @@ -1327,7 +1307,7 @@ " The Smiths\n", " [madchester, new wave, permanent wave, rock, u...\n", " 74\n", - " {'href': None, 'total': 4642841}\n", + " {'href': None, 'total': 4647089}\n", " \n", " \n", " 4\n", @@ -1335,15 +1315,15 @@ " Portishead\n", " [alternative rock, art pop, dark pop, electron...\n", " 59\n", - " {'href': None, 'total': 1850836}\n", + " {'href': None, 'total': 1851714}\n", " \n", " \n", " 5\n", " 432R46LaYsJZV2Gmc4jUV5\n", " Joy Division\n", - " [alternative rock, indie rock, madchester, new...\n", + " [alternative rock, art rock, indie rock, madch...\n", " 61\n", - " {'href': None, 'total': 2247194}\n", + " {'href': None, 'total': 2248108}\n", " \n", " \n", " 6\n", @@ -1351,7 +1331,7 @@ " The Cure\n", " [new wave, permanent wave, rock, uk post-punk]\n", " 73\n", - " {'href': None, 'total': 4883404}\n", + " {'href': None, 'total': 4886284}\n", " \n", " \n", " 7\n", @@ -1359,7 +1339,7 @@ " The Strokes\n", " [alternative rock, garage rock, modern rock, p...\n", " 73\n", - " {'href': None, 'total': 5258866}\n", + " {'href': None, 'total': 5260718}\n", " \n", " \n", " 8\n", @@ -1367,7 +1347,7 @@ " The Smashing Pumpkins\n", " [alternative metal, alternative rock, grunge, ...\n", " 70\n", - " {'href': None, 'total': 4760553}\n", + " {'href': None, 'total': 4762503}\n", " \n", " \n", " 9\n", @@ -1375,15 +1355,15 @@ " Sonic Youth\n", " [alternative rock, indie rock, noise pop, nois...\n", " 55\n", - " {'href': None, 'total': 1072268}\n", + " {'href': None, 'total': 1072692}\n", " \n", " \n", " 10\n", " 3G3Gdm0ZRAOxLrbyjfhii5\n", " my bloody valentine\n", " [alternative rock, dream pop, noise pop, shoeg...\n", - " 55\n", - " {'href': None, 'total': 810926}\n", + " 54\n", + " {'href': None, 'total': 811456}\n", " \n", " \n", " 11\n", @@ -1391,7 +1371,7 @@ " Slowdive\n", " [alternative rock, dream pop, nu gaze, reading...\n", " 60\n", - " {'href': None, 'total': 856978}\n", + " {'href': None, 'total': 857825}\n", " \n", " \n", " 12\n", @@ -1399,7 +1379,7 @@ " Björk\n", " [alternative rock, art pop, electronica, exper...\n", " 59\n", - " {'href': None, 'total': 1916375}\n", + " {'href': None, 'total': 1917156}\n", " \n", " \n", " 13\n", @@ -1407,7 +1387,7 @@ " Jeff Buckley\n", " [melancholia, permanent wave, singer-songwriter]\n", " 61\n", - " {'href': None, 'total': 1154600}\n", + " {'href': None, 'total': 1155378}\n", " \n", " \n", " 14\n", @@ -1415,7 +1395,7 @@ " Interpol\n", " [alternative dance, alternative rock, indie ro...\n", " 61\n", - " {'href': None, 'total': 1615840}\n", + " {'href': None, 'total': 1616230}\n", " \n", " \n", " 15\n", @@ -1423,7 +1403,7 @@ " Deftones\n", " [alternative metal, nu metal, rap metal, rock,...\n", " 75\n", - " {'href': None, 'total': 4540047}\n", + " {'href': None, 'total': 4543728}\n", " \n", " \n", " 16\n", @@ -1431,7 +1411,7 @@ " Arcade Fire\n", " [alternative rock, baroque pop, canadian indie...\n", " 62\n", - " {'href': None, 'total': 2233201}\n", + " {'href': None, 'total': 2233533}\n", " \n", " \n", " 17\n", @@ -1439,7 +1419,7 @@ " The Velvet Underground\n", " [alternative rock, melancholia, permanent wave...\n", " 60\n", - " {'href': None, 'total': 1799299}\n", + " {'href': None, 'total': 1800640}\n", " \n", " \n", " 18\n", @@ -1447,7 +1427,7 @@ " Massive Attack\n", " [downtempo, electronica, trip hop]\n", " 61\n", - " {'href': None, 'total': 2076307}\n", + " {'href': None, 'total': 2076951}\n", " \n", " \n", " 19\n", @@ -1455,7 +1435,7 @@ " Elliott Smith\n", " [alternative rock, indie rock, melancholia, si...\n", " 62\n", - " {'href': None, 'total': 1000064}\n", + " {'href': None, 'total': 1000573}\n", " \n", " \n", "\n", @@ -1490,12 +1470,12 @@ "2 [alternative rock, britpop, madchester, perman... 67 \n", "3 [madchester, new wave, permanent wave, rock, u... 74 \n", "4 [alternative rock, art pop, dark pop, electron... 59 \n", - "5 [alternative rock, indie rock, madchester, new... 61 \n", + "5 [alternative rock, art rock, indie rock, madch... 61 \n", "6 [new wave, permanent wave, rock, uk post-punk] 73 \n", "7 [alternative rock, garage rock, modern rock, p... 73 \n", "8 [alternative metal, alternative rock, grunge, ... 70 \n", "9 [alternative rock, indie rock, noise pop, nois... 55 \n", - "10 [alternative rock, dream pop, noise pop, shoeg... 55 \n", + "10 [alternative rock, dream pop, noise pop, shoeg... 54 \n", "11 [alternative rock, dream pop, nu gaze, reading... 60 \n", "12 [alternative rock, art pop, electronica, exper... 59 \n", "13 [melancholia, permanent wave, singer-songwriter] 61 \n", @@ -1507,52 +1487,48 @@ "19 [alternative rock, indie rock, melancholia, si... 62 \n", "\n", " related_followers \n", - "0 {'href': None, 'total': 984762} \n", - "1 {'href': None, 'total': 2692738} \n", - "2 {'href': None, 'total': 3098682} \n", - "3 {'href': None, 'total': 4642841} \n", - "4 {'href': None, 'total': 1850836} \n", - "5 {'href': None, 'total': 2247194} \n", - "6 {'href': None, 'total': 4883404} \n", - "7 {'href': None, 'total': 5258866} \n", - "8 {'href': None, 'total': 4760553} \n", - "9 {'href': None, 'total': 1072268} \n", - "10 {'href': None, 'total': 810926} \n", - "11 {'href': None, 'total': 856978} \n", - "12 {'href': None, 'total': 1916375} \n", - "13 {'href': None, 'total': 1154600} \n", - "14 {'href': None, 'total': 1615840} \n", - "15 {'href': None, 'total': 4540047} \n", - "16 {'href': None, 'total': 2233201} \n", - "17 {'href': None, 'total': 1799299} \n", - "18 {'href': None, 'total': 2076307} \n", - "19 {'href': None, 'total': 1000064} " + "0 {'href': None, 'total': 985116} \n", + "1 {'href': None, 'total': 2694003} \n", + "2 {'href': None, 'total': 3099793} \n", + "3 {'href': None, 'total': 4647089} \n", + "4 {'href': None, 'total': 1851714} \n", + "5 {'href': None, 'total': 2248108} \n", + "6 {'href': None, 'total': 4886284} \n", + "7 {'href': None, 'total': 5260718} \n", + "8 {'href': None, 'total': 4762503} \n", + "9 {'href': None, 'total': 1072692} \n", + "10 {'href': None, 'total': 811456} \n", + "11 {'href': None, 'total': 857825} \n", + "12 {'href': None, 'total': 1917156} \n", + "13 {'href': None, 'total': 1155378} \n", + "14 {'href': None, 'total': 1616230} \n", + "15 {'href': None, 'total': 4543728} \n", + "16 {'href': None, 'total': 2233533} \n", + "17 {'href': None, 'total': 1800640} \n", + "18 {'href': None, 'total': 2076951} \n", + "19 {'href': None, 'total': 1000573} " ] }, - "execution_count": 163, + "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "#rename de columns\n", + "df_related_artists = df_related_artists.rename(columns={'id': 'related_id',\n", + " 'name': 'related_name',\n", + " 'genres': 'related_genres',\n", + " 'popularity': 'related_popularity',\n", + " 'followers': 'related_followers'\n", + " })\n", "df_related_artists" ] }, { "cell_type": "code", - "execution_count": 168, - "id": "1c283965", - "metadata": {}, - "outputs": [], - "source": [ - "#add a column with selected id artist\n", - "df_related_artists['artist_id'] = artist_id" - ] - }, - { - "cell_type": "code", - "execution_count": 175, - "id": "ca482942", + "execution_count": 91, + "id": "fac7fc99", "metadata": {}, "outputs": [ { @@ -1577,46 +1553,868 @@ " \n", " \n", " related_id\n", - " related_name_x\n", - " related_genres_x\n", - " related_popularity_x\n", - " related_followers_x\n", + " related_name\n", + " related_genres\n", + " related_popularity\n", + " related_followers\n", " artist_id\n", - " related_name_y\n", - " related_genres_y\n", - " related_popularity_y\n", - " related_followers_y\n", " \n", " \n", " \n", + " \n", + " 0\n", + " 4CvTDPKA6W06DRfBnZKrau\n", + " Thom Yorke\n", + " [alternative rock, art pop, art rock, electron...\n", + " 54\n", + " {'href': None, 'total': 985116}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 1\n", + " 6zvul52xwTWzilBZl6BUbT\n", + " Pixies\n", + " [alternative rock, boston rock, permanent wave...\n", + " 68\n", + " {'href': None, 'total': 2694003}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 2\n", + " 7MhMgCo0Bl0Kukl93PZbYS\n", + " Blur\n", + " [alternative rock, britpop, madchester, perman...\n", + " 67\n", + " {'href': None, 'total': 3099793}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 3\n", + " 3yY2gUcIsjMr8hjo51PoJ8\n", + " The Smiths\n", + " [madchester, new wave, permanent wave, rock, u...\n", + " 74\n", + " {'href': None, 'total': 4647089}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 4\n", + " 6liAMWkVf5LH7YR9yfFy1Y\n", + " Portishead\n", + " [alternative rock, art pop, dark pop, electron...\n", + " 59\n", + " {'href': None, 'total': 1851714}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 5\n", + " 432R46LaYsJZV2Gmc4jUV5\n", + " Joy Division\n", + " [alternative rock, art rock, indie rock, madch...\n", + " 61\n", + " {'href': None, 'total': 2248108}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 6\n", + " 7bu3H8JO7d0UbMoVzbo70s\n", + " The Cure\n", + " [new wave, permanent wave, rock, uk post-punk]\n", + " 73\n", + " {'href': None, 'total': 4886284}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 7\n", + " 0epOFNiUfyON9EYx7Tpr6V\n", + " The Strokes\n", + " [alternative rock, garage rock, modern rock, p...\n", + " 73\n", + " {'href': None, 'total': 5260718}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 8\n", + " 40Yq4vzPs9VNUrIBG5Jr2i\n", + " The Smashing Pumpkins\n", + " [alternative metal, alternative rock, grunge, ...\n", + " 70\n", + " {'href': None, 'total': 4762503}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 9\n", + " 5UqTO8smerMvxHYA5xsXb6\n", + " Sonic Youth\n", + " [alternative rock, indie rock, noise pop, nois...\n", + " 55\n", + " {'href': None, 'total': 1072692}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 10\n", + " 3G3Gdm0ZRAOxLrbyjfhii5\n", + " my bloody valentine\n", + " [alternative rock, dream pop, noise pop, shoeg...\n", + " 54\n", + " {'href': None, 'total': 811456}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 11\n", + " 72X6FHxaShda0XeQw3vbeF\n", + " Slowdive\n", + " [alternative rock, dream pop, nu gaze, reading...\n", + " 60\n", + " {'href': None, 'total': 857825}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 12\n", + " 7w29UYBi0qsHi5RTcv3lmA\n", + " Björk\n", + " [alternative rock, art pop, electronica, exper...\n", + " 59\n", + " {'href': None, 'total': 1917156}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 13\n", + " 3nnQpaTvKb5jCQabZefACI\n", + " Jeff Buckley\n", + " [melancholia, permanent wave, singer-songwriter]\n", + " 61\n", + " {'href': None, 'total': 1155378}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 14\n", + " 3WaJSfKnzc65VDgmj2zU8B\n", + " Interpol\n", + " [alternative dance, alternative rock, indie ro...\n", + " 61\n", + " {'href': None, 'total': 1616230}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 15\n", + " 6Ghvu1VvMGScGpOUJBAHNH\n", + " Deftones\n", + " [alternative metal, nu metal, rap metal, rock,...\n", + " 75\n", + " {'href': None, 'total': 4543728}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 16\n", + " 3kjuyTCjPG1WMFCiyc5IuB\n", + " Arcade Fire\n", + " [alternative rock, baroque pop, canadian indie...\n", + " 62\n", + " {'href': None, 'total': 2233533}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 17\n", + " 1nJvji2KIlWSseXRSlNYsC\n", + " The Velvet Underground\n", + " [alternative rock, melancholia, permanent wave...\n", + " 60\n", + " {'href': None, 'total': 1800640}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 18\n", + " 6FXMGgJwohJLUSr5nVlf9X\n", + " Massive Attack\n", + " [downtempo, electronica, trip hop]\n", + " 61\n", + " {'href': None, 'total': 2076951}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", + " \n", + " 19\n", + " 2ApaG60P4r0yhBoDCGD8YG\n", + " Elliott Smith\n", + " [alternative rock, indie rock, melancholia, si...\n", + " 62\n", + " {'href': None, 'total': 1000573}\n", + " 4Z8W4fKeB5YxbusRsdQVPb\n", + " \n", " \n", "\n", "" ], "text/plain": [ - "Empty DataFrame\n", - "Columns: [related_id, related_name_x, related_genres_x, related_popularity_x, related_followers_x, artist_id, related_name_y, related_genres_y, related_popularity_y, related_followers_y]\n", - "Index: []" - ] - }, - "execution_count": 175, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#join artist and related artist to merge info\n", - "df_related_artists = pd.merge(df_related_artists, df_artist, on='related_id')\n", - "df_related_artists" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9213fd43", - "metadata": {}, - "outputs": [], - "source": [] + " related_id related_name \\\n", + "0 4CvTDPKA6W06DRfBnZKrau Thom Yorke \n", + "1 6zvul52xwTWzilBZl6BUbT Pixies \n", + "2 7MhMgCo0Bl0Kukl93PZbYS Blur \n", + "3 3yY2gUcIsjMr8hjo51PoJ8 The Smiths \n", + "4 6liAMWkVf5LH7YR9yfFy1Y Portishead \n", + "5 432R46LaYsJZV2Gmc4jUV5 Joy Division \n", + "6 7bu3H8JO7d0UbMoVzbo70s The Cure \n", + "7 0epOFNiUfyON9EYx7Tpr6V The Strokes \n", + "8 40Yq4vzPs9VNUrIBG5Jr2i The Smashing Pumpkins \n", + "9 5UqTO8smerMvxHYA5xsXb6 Sonic Youth \n", + "10 3G3Gdm0ZRAOxLrbyjfhii5 my bloody valentine \n", + "11 72X6FHxaShda0XeQw3vbeF Slowdive \n", + "12 7w29UYBi0qsHi5RTcv3lmA Björk \n", + "13 3nnQpaTvKb5jCQabZefACI Jeff Buckley \n", + "14 3WaJSfKnzc65VDgmj2zU8B Interpol \n", + "15 6Ghvu1VvMGScGpOUJBAHNH Deftones \n", + "16 3kjuyTCjPG1WMFCiyc5IuB Arcade Fire \n", + "17 1nJvji2KIlWSseXRSlNYsC The Velvet Underground \n", + "18 6FXMGgJwohJLUSr5nVlf9X Massive Attack \n", + "19 2ApaG60P4r0yhBoDCGD8YG Elliott Smith \n", + "\n", + " related_genres related_popularity \\\n", + "0 [alternative rock, art pop, art rock, electron... 54 \n", + "1 [alternative rock, boston rock, permanent wave... 68 \n", + "2 [alternative rock, britpop, madchester, perman... 67 \n", + "3 [madchester, new wave, permanent wave, rock, u... 74 \n", + "4 [alternative rock, art pop, dark pop, electron... 59 \n", + "5 [alternative rock, art rock, indie rock, madch... 61 \n", + "6 [new wave, permanent wave, rock, uk post-punk] 73 \n", + "7 [alternative rock, garage rock, modern rock, p... 73 \n", + "8 [alternative metal, alternative rock, grunge, ... 70 \n", + "9 [alternative rock, indie rock, noise pop, nois... 55 \n", + "10 [alternative rock, dream pop, noise pop, shoeg... 54 \n", + "11 [alternative rock, dream pop, nu gaze, reading... 60 \n", + "12 [alternative rock, art pop, electronica, exper... 59 \n", + "13 [melancholia, permanent wave, singer-songwriter] 61 \n", + "14 [alternative dance, alternative rock, indie ro... 61 \n", + "15 [alternative metal, nu metal, rap metal, rock,... 75 \n", + "16 [alternative rock, baroque pop, canadian indie... 62 \n", + "17 [alternative rock, melancholia, permanent wave... 60 \n", + "18 [downtempo, electronica, trip hop] 61 \n", + "19 [alternative rock, indie rock, melancholia, si... 62 \n", + "\n", + " related_followers artist_id \n", + "0 {'href': None, 'total': 985116} 4Z8W4fKeB5YxbusRsdQVPb \n", + "1 {'href': None, 'total': 2694003} 4Z8W4fKeB5YxbusRsdQVPb \n", + "2 {'href': None, 'total': 3099793} 4Z8W4fKeB5YxbusRsdQVPb \n", + "3 {'href': None, 'total': 4647089} 4Z8W4fKeB5YxbusRsdQVPb \n", + "4 {'href': None, 'total': 1851714} 4Z8W4fKeB5YxbusRsdQVPb \n", + "5 {'href': None, 'total': 2248108} 4Z8W4fKeB5YxbusRsdQVPb \n", + "6 {'href': None, 'total': 4886284} 4Z8W4fKeB5YxbusRsdQVPb \n", + "7 {'href': None, 'total': 5260718} 4Z8W4fKeB5YxbusRsdQVPb \n", + "8 {'href': None, 'total': 4762503} 4Z8W4fKeB5YxbusRsdQVPb \n", + "9 {'href': None, 'total': 1072692} 4Z8W4fKeB5YxbusRsdQVPb \n", + "10 {'href': None, 'total': 811456} 4Z8W4fKeB5YxbusRsdQVPb \n", + "11 {'href': None, 'total': 857825} 4Z8W4fKeB5YxbusRsdQVPb \n", + "12 {'href': None, 'total': 1917156} 4Z8W4fKeB5YxbusRsdQVPb \n", + "13 {'href': None, 'total': 1155378} 4Z8W4fKeB5YxbusRsdQVPb \n", + "14 {'href': None, 'total': 1616230} 4Z8W4fKeB5YxbusRsdQVPb \n", + "15 {'href': None, 'total': 4543728} 4Z8W4fKeB5YxbusRsdQVPb \n", + "16 {'href': None, 'total': 2233533} 4Z8W4fKeB5YxbusRsdQVPb \n", + "17 {'href': None, 'total': 1800640} 4Z8W4fKeB5YxbusRsdQVPb \n", + "18 {'href': None, 'total': 2076951} 4Z8W4fKeB5YxbusRsdQVPb \n", + "19 {'href': None, 'total': 1000573} 4Z8W4fKeB5YxbusRsdQVPb " + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#add a column with selected id artist\n", + "df_related_artists['artist_id'] = artist_id\n", + "df_related_artists\n", + "#añadimos artist_id en df_related_artists" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "e94bdf9a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
related_idrelated_namerelated_genresrelated_popularityrelated_followersartist_idnamegenrespopularityfollowers
04CvTDPKA6W06DRfBnZKrauThom Yorke[alternative rock, art pop, art rock, electron...54{'href': None, 'total': 985116}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
16zvul52xwTWzilBZl6BUbTPixies[alternative rock, boston rock, permanent wave...68{'href': None, 'total': 2694003}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
27MhMgCo0Bl0Kukl93PZbYSBlur[alternative rock, britpop, madchester, perman...67{'href': None, 'total': 3099793}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
33yY2gUcIsjMr8hjo51PoJ8The Smiths[madchester, new wave, permanent wave, rock, u...74{'href': None, 'total': 4647089}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
46liAMWkVf5LH7YR9yfFy1YPortishead[alternative rock, art pop, dark pop, electron...59{'href': None, 'total': 1851714}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
5432R46LaYsJZV2Gmc4jUV5Joy Division[alternative rock, art rock, indie rock, madch...61{'href': None, 'total': 2248108}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
67bu3H8JO7d0UbMoVzbo70sThe Cure[new wave, permanent wave, rock, uk post-punk]73{'href': None, 'total': 4886284}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
70epOFNiUfyON9EYx7Tpr6VThe Strokes[alternative rock, garage rock, modern rock, p...73{'href': None, 'total': 5260718}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
840Yq4vzPs9VNUrIBG5Jr2iThe Smashing Pumpkins[alternative metal, alternative rock, grunge, ...70{'href': None, 'total': 4762503}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
95UqTO8smerMvxHYA5xsXb6Sonic Youth[alternative rock, indie rock, noise pop, nois...55{'href': None, 'total': 1072692}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
103G3Gdm0ZRAOxLrbyjfhii5my bloody valentine[alternative rock, dream pop, noise pop, shoeg...54{'href': None, 'total': 811456}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
1172X6FHxaShda0XeQw3vbeFSlowdive[alternative rock, dream pop, nu gaze, reading...60{'href': None, 'total': 857825}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
127w29UYBi0qsHi5RTcv3lmABjörk[alternative rock, art pop, electronica, exper...59{'href': None, 'total': 1917156}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
133nnQpaTvKb5jCQabZefACIJeff Buckley[melancholia, permanent wave, singer-songwriter]61{'href': None, 'total': 1155378}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
143WaJSfKnzc65VDgmj2zU8BInterpol[alternative dance, alternative rock, indie ro...61{'href': None, 'total': 1616230}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
156Ghvu1VvMGScGpOUJBAHNHDeftones[alternative metal, nu metal, rap metal, rock,...75{'href': None, 'total': 4543728}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
163kjuyTCjPG1WMFCiyc5IuBArcade Fire[alternative rock, baroque pop, canadian indie...62{'href': None, 'total': 2233533}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
171nJvji2KIlWSseXRSlNYsCThe Velvet Underground[alternative rock, melancholia, permanent wave...60{'href': None, 'total': 1800640}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
186FXMGgJwohJLUSr5nVlf9XMassive Attack[downtempo, electronica, trip hop]61{'href': None, 'total': 2076951}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
192ApaG60P4r0yhBoDCGD8YGElliott Smith[alternative rock, indie rock, melancholia, si...62{'href': None, 'total': 1000573}4Z8W4fKeB5YxbusRsdQVPbRadiohead[alternative rock, art rock, melancholia, oxfo...78{'href': None, 'total': 8884416}
\n", + "
" + ], + "text/plain": [ + " related_id related_name \\\n", + "0 4CvTDPKA6W06DRfBnZKrau Thom Yorke \n", + "1 6zvul52xwTWzilBZl6BUbT Pixies \n", + "2 7MhMgCo0Bl0Kukl93PZbYS Blur \n", + "3 3yY2gUcIsjMr8hjo51PoJ8 The Smiths \n", + "4 6liAMWkVf5LH7YR9yfFy1Y Portishead \n", + "5 432R46LaYsJZV2Gmc4jUV5 Joy Division \n", + "6 7bu3H8JO7d0UbMoVzbo70s The Cure \n", + "7 0epOFNiUfyON9EYx7Tpr6V The Strokes \n", + "8 40Yq4vzPs9VNUrIBG5Jr2i The Smashing Pumpkins \n", + "9 5UqTO8smerMvxHYA5xsXb6 Sonic Youth \n", + "10 3G3Gdm0ZRAOxLrbyjfhii5 my bloody valentine \n", + "11 72X6FHxaShda0XeQw3vbeF Slowdive \n", + "12 7w29UYBi0qsHi5RTcv3lmA Björk \n", + "13 3nnQpaTvKb5jCQabZefACI Jeff Buckley \n", + "14 3WaJSfKnzc65VDgmj2zU8B Interpol \n", + "15 6Ghvu1VvMGScGpOUJBAHNH Deftones \n", + "16 3kjuyTCjPG1WMFCiyc5IuB Arcade Fire \n", + "17 1nJvji2KIlWSseXRSlNYsC The Velvet Underground \n", + "18 6FXMGgJwohJLUSr5nVlf9X Massive Attack \n", + "19 2ApaG60P4r0yhBoDCGD8YG Elliott Smith \n", + "\n", + " related_genres related_popularity \\\n", + "0 [alternative rock, art pop, art rock, electron... 54 \n", + "1 [alternative rock, boston rock, permanent wave... 68 \n", + "2 [alternative rock, britpop, madchester, perman... 67 \n", + "3 [madchester, new wave, permanent wave, rock, u... 74 \n", + "4 [alternative rock, art pop, dark pop, electron... 59 \n", + "5 [alternative rock, art rock, indie rock, madch... 61 \n", + "6 [new wave, permanent wave, rock, uk post-punk] 73 \n", + "7 [alternative rock, garage rock, modern rock, p... 73 \n", + "8 [alternative metal, alternative rock, grunge, ... 70 \n", + "9 [alternative rock, indie rock, noise pop, nois... 55 \n", + "10 [alternative rock, dream pop, noise pop, shoeg... 54 \n", + "11 [alternative rock, dream pop, nu gaze, reading... 60 \n", + "12 [alternative rock, art pop, electronica, exper... 59 \n", + "13 [melancholia, permanent wave, singer-songwriter] 61 \n", + "14 [alternative dance, alternative rock, indie ro... 61 \n", + "15 [alternative metal, nu metal, rap metal, rock,... 75 \n", + "16 [alternative rock, baroque pop, canadian indie... 62 \n", + "17 [alternative rock, melancholia, permanent wave... 60 \n", + "18 [downtempo, electronica, trip hop] 61 \n", + "19 [alternative rock, indie rock, melancholia, si... 62 \n", + "\n", + " related_followers artist_id name \\\n", + "0 {'href': None, 'total': 985116} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "1 {'href': None, 'total': 2694003} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "2 {'href': None, 'total': 3099793} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "3 {'href': None, 'total': 4647089} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "4 {'href': None, 'total': 1851714} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "5 {'href': None, 'total': 2248108} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "6 {'href': None, 'total': 4886284} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "7 {'href': None, 'total': 5260718} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "8 {'href': None, 'total': 4762503} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "9 {'href': None, 'total': 1072692} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "10 {'href': None, 'total': 811456} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "11 {'href': None, 'total': 857825} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "12 {'href': None, 'total': 1917156} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "13 {'href': None, 'total': 1155378} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "14 {'href': None, 'total': 1616230} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "15 {'href': None, 'total': 4543728} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "16 {'href': None, 'total': 2233533} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "17 {'href': None, 'total': 1800640} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "18 {'href': None, 'total': 2076951} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "19 {'href': None, 'total': 1000573} 4Z8W4fKeB5YxbusRsdQVPb Radiohead \n", + "\n", + " genres popularity \\\n", + "0 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "1 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "2 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "3 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "4 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "5 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "6 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "7 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "8 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "9 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "10 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "11 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "12 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "13 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "14 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "15 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "16 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "17 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "18 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "19 [alternative rock, art rock, melancholia, oxfo... 78 \n", + "\n", + " followers \n", + "0 {'href': None, 'total': 8884416} \n", + "1 {'href': None, 'total': 8884416} \n", + "2 {'href': None, 'total': 8884416} \n", + "3 {'href': None, 'total': 8884416} \n", + "4 {'href': None, 'total': 8884416} \n", + "5 {'href': None, 'total': 8884416} \n", + "6 {'href': None, 'total': 8884416} \n", + "7 {'href': None, 'total': 8884416} \n", + "8 {'href': None, 'total': 8884416} \n", + "9 {'href': None, 'total': 8884416} \n", + "10 {'href': None, 'total': 8884416} \n", + "11 {'href': None, 'total': 8884416} \n", + "12 {'href': None, 'total': 8884416} \n", + "13 {'href': None, 'total': 8884416} \n", + "14 {'href': None, 'total': 8884416} \n", + "15 {'href': None, 'total': 8884416} \n", + "16 {'href': None, 'total': 8884416} \n", + "17 {'href': None, 'total': 8884416} \n", + "18 {'href': None, 'total': 8884416} \n", + "19 {'href': None, 'total': 8884416} " + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_related_artists = pd.merge(df_related_artists, df_artist, on=\"artist_id\")\n", + "df_related_artists\n", + "#unimos df_related_artists y df_artist" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "id": "77adb8d5", + "metadata": {}, + "outputs": [], + "source": [ + "my_list=list()# tengo una lista vacia\n", + "for x in df_related_artists['related_id'].to_list():#por cada elemento en related_id lo conviertes a lista\n", + " method = \"/top-tracks\"\n", + " argument = \"?market=ES\" # aqui creamos el full_endpoint\n", + " full_endpoint = base_url + resource + x + method + argument # por cada artists_id una llamada a top-tracks\n", + " my_list.append(requests.get(full_endpoint, headers = header_info).json())#meto en la lista vacia\n", + " #los top-tracks de cada artista relacionado" + ] + }, + { + "cell_type": "code", + "execution_count": 141, + "id": "b0d1a47c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Thom Yorke'" + ] + }, + "execution_count": 141, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#my_list[0]['tracks'][0]['artists'][0]['name']" + ] + }, + { + "cell_type": "code", + "execution_count": 144, + "id": "725573aa", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
artist_nametrack_name
0Thom YorkeHearing Damage
1Thom YorkeSuspirium
2Thom YorkeDawn Chorus
3Thom YorkeBlack Swan
4Thom YorkeUnmade
.........
195Elliott SmithSomebody That I Used To Know
196Elliott SmithBallad Of Big Nothing
197Elliott SmithSpeed Trials
198Elliott SmithClementine
199Elliott SmithSon Of Sam
\n", + "

200 rows × 2 columns

\n", + "
" + ], + "text/plain": [ + " artist_name track_name\n", + "0 Thom Yorke Hearing Damage\n", + "1 Thom Yorke Suspirium\n", + "2 Thom Yorke Dawn Chorus\n", + "3 Thom Yorke Black Swan\n", + "4 Thom Yorke Unmade\n", + ".. ... ...\n", + "195 Elliott Smith Somebody That I Used To Know\n", + "196 Elliott Smith Ballad Of Big Nothing\n", + "197 Elliott Smith Speed Trials\n", + "198 Elliott Smith Clementine\n", + "199 Elliott Smith Son Of Sam\n", + "\n", + "[200 rows x 2 columns]" + ] + }, + "execution_count": 144, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list_2 = list()#creo una lista 2\n", + "for x in range(len(my_list)): # por cada elemento del rango de la longitud de my_list esto recorre cada artista\n", + " for y in range(len(my_list[x]['tracks'])):#este recorre cada track de cada artista\n", + " my_list_2.append([my_list[x]['tracks'][y]['artists'][0]['name'], my_list[x]['tracks'][y]['name']])\n", + " #En mi lista_2 metemos el nombre del artista y cada cancion\n", + " #tenemos 20 artistas y 10 canciones por cada artista\n", + "my_list_2\n", + "pd.DataFrame(my_list_2, columns=['artist_name','track_name'])#convertimos la lista a un DataFrame de 2 columnas artista y tracks" + ] }, { "cell_type": "markdown",