From 1e1ce321a4af7b5ccd424eeff37d0ebc439a1dbd Mon Sep 17 00:00:00 2001 From: Andrew Bavuels Date: Fri, 3 Nov 2023 23:00:09 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Hasta=20aqu=C3=AD=20llegu=C3=A9=20y=20no=20?= =?UTF-8?q?he=20podido=20lograr=20con=20=C3=A9xito=20el=20total=20de=2020?= =?UTF-8?q?=20artistas=20x=2010=20top=20tracks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- notebooks/spotify_rest_api_challenge.ipynb | 2095 +++++++++++++++++++- 1 file changed, 2052 insertions(+), 43 deletions(-) diff --git a/notebooks/spotify_rest_api_challenge.ipynb b/notebooks/spotify_rest_api_challenge.ipynb index 5e4f8f7..169e30b 100644 --- a/notebooks/spotify_rest_api_challenge.ipynb +++ b/notebooks/spotify_rest_api_challenge.ipynb @@ -16,14 +16,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 923, "id": "17a49776", "metadata": {}, "outputs": [], "source": [ "# Imports\n", - "\n", - "\n" + "import pandas as pd\n", + "import requests\n", + "import numpy as np" ] }, { @@ -38,21 +39,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 924, "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 = 'bec9dd918ed04aca96b6eb3c699e443f'# CLIENT ID\n", + "client_secret = 'aafa5d5b0a44425b80336b4e57688b9c'# CLIENT SECRET\n", "auth_url = 'https://accounts.spotify.com/api/token'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 925, "id": "c7901d1e", "metadata": {}, "outputs": [], @@ -64,10 +65,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 926, "id": "262e7e18", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'access_token': 'BQD0ZISBlKm0lyo5kc_v4hEF7aGhjlx8--YMWnly2Qm2Zzr5RLjfw1ElRBOdT9p-gh6FAEqSW7SaE5gGHHSoYQpzaSPsZbo3HREpddsO5BdmpoStWnQ',\n", + " 'token_type': 'Bearer',\n", + " 'expires_in': 3600}" + ] + }, + "execution_count": 926, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "access_token = auth_response['access_token']\n", "auth_response" @@ -85,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 927, "id": "62e6d4fb", "metadata": {}, "outputs": [], @@ -93,11 +107,30 @@ "# 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)}" ] }, + { + "cell_type": "code", + "execution_count": 928, + "id": "a293e6e7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Authorization': 'Bearer BQD0ZISBlKm0lyo5kc_v4hEF7aGhjlx8--YMWnly2Qm2Zzr5RLjfw1ElRBOdT9p-gh6FAEqSW7SaE5gGHHSoYQpzaSPsZbo3HREpddsO5BdmpoStWnQ'}" + ] + }, + "execution_count": 928, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "header_info" + ] + }, { "cell_type": "markdown", "id": "16660a9b", @@ -109,31 +142,31 @@ "\n", "__Here you have the different artists to start with:__\n", "\n", - "- __Option 1:__ 0L8ExT028jH3ddEcZwqJJ5\n", + "- __Option 1:__ 0L8ExT028jH3ddEcZwqJJ5 `\"Sublime!\"`\n", "\n", - "- __Option 2:__ 4Y7tXHSEejGu1vQ9bwDdXW\n", + "- __Option 2:__ 4Y7tXHSEejGu1vQ9bwDdXW `\"Sublime!\"`\n", "\n", - "- __Option 3:__ 6FBDaR13swtiWwGhX1WQsP\n", + "- __Option 3:__ 6FBDaR13swtiWwGhX1WQsP `\"Mmmmm...ok!\"`\n", "\n", - "- __Option 4:__ 0kyQwKHCZnKE7kTXkxXjrB\n", + "- __Option 4:__ 0kyQwKHCZnKE7kTXkxXjrB `\"Not my faves!\"`\n", "\n", - "- __Option 5:__ 2d0hyoQ5ynDBnkvAbJKORj\n", + "- __Option 5:__ 2d0hyoQ5ynDBnkvAbJKORj `\"Sublime!\"`\n", "\n", - "- __Option 6:__ 3bgsNtcf5d5h9jbQbohfBK\n", + "- __Option 6:__ 3bgsNtcf5d5h9jbQbohfBK `\"Not my faves!\"`\n", "\n", - "- __Option 7:__ 7mWCSSOYqm4E9mB7V4ot6S\n", + "- __Option 7:__ 7mWCSSOYqm4E9mB7V4ot6S `\"Not my faves!\"`\n", "\n", - "- __Option 8:__ 64KEffDW9EtZ1y2vBYgq8T\n", + "- __Option 8:__ 64KEffDW9EtZ1y2vBYgq8T `\"Moody ones!\"`\n", "\n", - "- __Option 9:__ 4k1ELeJKT1ISyDv8JivPpB\n", + "- __Option 9:__ 4k1ELeJKT1ISyDv8JivPpB `\"Some serious shit!\"`\n", "\n", - "- __Option 10:__ 4Z8W4fKeB5YxbusRsdQVPb\n", + "- __Option 10:__ 4Z8W4fKeB5YxbusRsdQVPb `\"Some serious shit!\"`\n", "\n", - "- __Option 11:__ 26dSoYclwsYLMAKD3tpOr4\n", + "- __Option 11:__ 26dSoYclwsYLMAKD3tpOr4 `\"It fucking sucks as shit!\"`\n", "\n", - "- __Option 12:__ 7y97mc3bZRFXzT2szRM4L4\n", + "- __Option 12:__ 7y97mc3bZRFXzT2szRM4L4 `Sip of wine and \"hohohohoh!\" (Intellectual laugh)`\n", "\n", - "- __Option 13:__ 1w5Kfo2jwwIPruYS2UWh56\n", + "- __Option 13:__ 1w5Kfo2jwwIPruYS2UWh56 `\"Sublime!\"`\n", "\n", "\n", "> Remember to check the [Requests](https://requests.readthedocs.io/en/latest/) library docs!!!\n", @@ -141,29 +174,2013 @@ "---" ] }, + { + "cell_type": "markdown", + "id": "69fd5c14", + "metadata": {}, + "source": [ + "### 1. Artist chosen (Option 1):\n", + "\n", + "#### Red Hot Chili Peppers - Give it away\n", + "\n", + "![give_it_away](https://i.gifer.com/No0a.gif)" + ] + }, { "cell_type": "code", - "execution_count": null, - "id": "04f85940", + "execution_count": 929, + "id": "51426ff7", "metadata": {}, "outputs": [], "source": [ - "# Here you can complete your endpoint URI\n", + "artist_id = '0L8ExT028jH3ddEcZwqJJ5'" + ] + }, + { + "cell_type": "code", + "execution_count": 930, + "id": "4cab465e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5\n" + ] + } + ], + "source": [ + "# Build the url for API call:\n", + "resource = 'artists' # Viene de la documentación\n", + "parameters = f'/{artist_id}'\n", + "\n", + "url = base_url + resource + parameters\n", + "print(url)" + ] + }, + { + "cell_type": "code", + "execution_count": 931, + "id": "4830ee02", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 931, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# API call\n", + "artist_response = requests.get(url, headers=header_info)\n", + "artist_response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": 932, + "id": "c64da635", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'followers': {'href': None, 'total': 20243794},\n", + " 'genres': ['alternative rock',\n", + " 'funk metal',\n", + " 'funk rock',\n", + " 'permanent wave',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebc33cc15260b767ddec982ce8',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174c33cc15260b767ddec982ce8',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178c33cc15260b767ddec982ce8',\n", + " 'width': 160}],\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'popularity': 80,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}" + ] + }, + "execution_count": 932, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "artist_json = artist_response.json()\n", + "artist_json" + ] + }, + { + "cell_type": "code", + "execution_count": 933, + "id": "dd4e105c", + "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", + "
external_urlsfollowersgenreshrefidimagesnamepopularitytypeuriartist_id
0{'spotify': 'https://open.spotify.com/artist/0...{'href': None, 'total': 20243794}[alternative rock, funk metal, funk rock, perm...https://api.spotify.com/v1/artists/0L8ExT028jH...0L8ExT028jH3ddEcZwqJJ5[{'height': 640, 'url': 'https://i.scdn.co/ima...Red Hot Chili Peppers80artistspotify:artist:0L8ExT028jH3ddEcZwqJJ50L8ExT028jH3ddEcZwqJJ5
\n", + "
" + ], + "text/plain": [ + " external_urls \\\n", + "0 {'spotify': 'https://open.spotify.com/artist/0... \n", + "\n", + " followers \\\n", + "0 {'href': None, 'total': 20243794} \n", + "\n", + " genres \\\n", + "0 [alternative rock, funk metal, funk rock, perm... \n", + "\n", + " href id \\\n", + "0 https://api.spotify.com/v1/artists/0L8ExT028jH... 0L8ExT028jH3ddEcZwqJJ5 \n", + "\n", + " images name \\\n", + "0 [{'height': 640, 'url': 'https://i.scdn.co/ima... Red Hot Chili Peppers \n", + "\n", + " popularity type uri \\\n", + "0 80 artist spotify:artist:0L8ExT028jH3ddEcZwqJJ5 \n", + "\n", + " artist_id \n", + "0 0L8ExT028jH3ddEcZwqJJ5 " + ] + }, + "execution_count": 933, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Create DataFrames\n", + "artist_df = pd.DataFrame([artist_json])\n", + "artist_df['artist_id'] = artist_id\n", + "artist_df" + ] + }, + { + "cell_type": "code", + "execution_count": 953, + "id": "f5966220", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index(['external_urls', 'followers', 'genres', 'href', 'id', 'images', 'name',\n", + " 'popularity', 'type', 'uri', 'artist_id'],\n", + " dtype='object')\n" + ] + } + ], + "source": [ + "print(artist_df.columns)" + ] + }, + { + "cell_type": "markdown", + "id": "11cbe450", + "metadata": {}, + "source": [ + "### 2. Top-tracks" + ] + }, + { + "cell_type": "code", + "execution_count": 954, + "id": "a1854027", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5/top-tracks?market=ES'" + ] + }, + "execution_count": 954, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Get top tracks\n", + "method = '/top-tracks'\n", + "argument = '?market=ES'\n", + "full_endpoint = base_url + resource + parameters + method + argument\n", + "full_endpoint" + ] + }, + { + "cell_type": "code", + "execution_count": 955, + "id": "6ffbf563", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 955, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "top_tracks_response = requests.get(full_endpoint, headers = header_info)\n", + "top_tracks_response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": 956, + "id": "050efac3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'tracks': [{'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/30Perjew8HyGkdSmqguYyg'},\n", + " 'href': 'https://api.spotify.com/v1/albums/30Perjew8HyGkdSmqguYyg',\n", + " 'id': '30Perjew8HyGkdSmqguYyg',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b273153d79816d853f2694b2cc70',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e02153d79816d853f2694b2cc70',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00004851153d79816d853f2694b2cc70',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Blood Sugar Sex Magik (Deluxe Edition)',\n", + " 'release_date': '1991-09-24',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 19,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:30Perjew8HyGkdSmqguYyg'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 264306,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USWB19901576'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/3d9DChrdc6BOeFsbrZ3Is0'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/3d9DChrdc6BOeFsbrZ3Is0',\n", + " 'id': '3d9DChrdc6BOeFsbrZ3Is0',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Under the Bridge',\n", + " 'popularity': 87,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/46b0229c06712c5b5e143724c0617e51a9b6e432?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 11,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:3d9DChrdc6BOeFsbrZ3Is0'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/2Y9IRtehByVkegoD7TcLfi'},\n", + " 'href': 'https://api.spotify.com/v1/albums/2Y9IRtehByVkegoD7TcLfi',\n", + " 'id': '2Y9IRtehByVkegoD7TcLfi',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b27394d08ab63e57b0cae74e8595',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e0294d08ab63e57b0cae74e8595',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000485194d08ab63e57b0cae74e8595',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Californication (Deluxe Edition)',\n", + " 'release_date': '1999-06-08',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 18,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:2Y9IRtehByVkegoD7TcLfi'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 329733,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USWB19900690'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/48UPSzbZjgc449aqz8bxox'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/48UPSzbZjgc449aqz8bxox',\n", + " 'id': '48UPSzbZjgc449aqz8bxox',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Californication',\n", + " 'popularity': 86,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/0fd595c5b63db10f4a99683f8248ea5d13700683?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 6,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:48UPSzbZjgc449aqz8bxox'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/6deiaArbeoqp1xPEGdEKp1'},\n", + " 'href': 'https://api.spotify.com/v1/albums/6deiaArbeoqp1xPEGdEKp1',\n", + " 'id': '6deiaArbeoqp1xPEGdEKp1',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b273de1af2785a83cc660155a0c4',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e02de1af2785a83cc660155a0c4',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00004851de1af2785a83cc660155a0c4',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'By the Way (Deluxe Edition)',\n", + " 'release_date': '2002-07-09',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 18,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:6deiaArbeoqp1xPEGdEKp1'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 269000,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USWB10201694'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/3ZOEytgrvLwQaqXreDs2Jx'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/3ZOEytgrvLwQaqXreDs2Jx',\n", + " 'id': '3ZOEytgrvLwQaqXreDs2Jx',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': \"Can't Stop\",\n", + " 'popularity': 85,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/1b3bc0aca1746a99cbb8dd07b2325f6499b58a2e?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 7,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:3ZOEytgrvLwQaqXreDs2Jx'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/2Y9IRtehByVkegoD7TcLfi'},\n", + " 'href': 'https://api.spotify.com/v1/albums/2Y9IRtehByVkegoD7TcLfi',\n", + " 'id': '2Y9IRtehByVkegoD7TcLfi',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b27394d08ab63e57b0cae74e8595',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e0294d08ab63e57b0cae74e8595',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000485194d08ab63e57b0cae74e8595',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Californication (Deluxe Edition)',\n", + " 'release_date': '1999-06-08',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 18,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:2Y9IRtehByVkegoD7TcLfi'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 215906,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USWB19900674'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/1G391cbiT3v3Cywg8T7DM1'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/1G391cbiT3v3Cywg8T7DM1',\n", + " 'id': '1G391cbiT3v3Cywg8T7DM1',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Scar Tissue',\n", + " 'popularity': 84,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/5aa4aff376bccc73f7fa7df2954649e30a56c4b1?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 3,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:1G391cbiT3v3Cywg8T7DM1'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/2Y9IRtehByVkegoD7TcLfi'},\n", + " 'href': 'https://api.spotify.com/v1/albums/2Y9IRtehByVkegoD7TcLfi',\n", + " 'id': '2Y9IRtehByVkegoD7TcLfi',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b27394d08ab63e57b0cae74e8595',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e0294d08ab63e57b0cae74e8595',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000485194d08ab63e57b0cae74e8595',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Californication (Deluxe Edition)',\n", + " 'release_date': '1999-06-08',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 18,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:2Y9IRtehByVkegoD7TcLfi'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 255373,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USWB19900693'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/64BbK9SFKH2jk86U3dGj2P'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/64BbK9SFKH2jk86U3dGj2P',\n", + " 'id': '64BbK9SFKH2jk86U3dGj2P',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Otherside',\n", + " 'popularity': 83,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/90076510970ced8308b85cd65776f75b99d97e7f?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 4,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:64BbK9SFKH2jk86U3dGj2P'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/7xl50xr9NDkd3i2kBbzsNZ'},\n", + " 'href': 'https://api.spotify.com/v1/albums/7xl50xr9NDkd3i2kBbzsNZ',\n", + " 'id': '7xl50xr9NDkd3i2kBbzsNZ',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b27309fd83d32aee93dceba78517',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e0209fd83d32aee93dceba78517',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000485109fd83d32aee93dceba78517',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Stadium Arcadium',\n", + " 'release_date': '2006-05-09',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 29,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:7xl50xr9NDkd3i2kBbzsNZ'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 334666,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USWB10601591'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/2aibwv5hGXSgw7Yru8IYTO'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/2aibwv5hGXSgw7Yru8IYTO',\n", + " 'id': '2aibwv5hGXSgw7Yru8IYTO',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Snow (Hey Oh)',\n", + " 'popularity': 81,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/d1e419a7f2aa9ba761be88802dbd3560b8f99776?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 2,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:2aibwv5hGXSgw7Yru8IYTO'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/7xl50xr9NDkd3i2kBbzsNZ'},\n", + " 'href': 'https://api.spotify.com/v1/albums/7xl50xr9NDkd3i2kBbzsNZ',\n", + " 'id': '7xl50xr9NDkd3i2kBbzsNZ',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b27309fd83d32aee93dceba78517',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e0209fd83d32aee93dceba78517',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000485109fd83d32aee93dceba78517',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Stadium Arcadium',\n", + " 'release_date': '2006-05-09',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 29,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:7xl50xr9NDkd3i2kBbzsNZ'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 282160,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USWB10600700'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/10Nmj3JCNoMeBQ87uw5j8k'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/10Nmj3JCNoMeBQ87uw5j8k',\n", + " 'id': '10Nmj3JCNoMeBQ87uw5j8k',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Dani California',\n", + " 'popularity': 80,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/0454b7cef05f7db734eb04bd4f3948009838f380?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 1,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:10Nmj3JCNoMeBQ87uw5j8k'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/6deiaArbeoqp1xPEGdEKp1'},\n", + " 'href': 'https://api.spotify.com/v1/albums/6deiaArbeoqp1xPEGdEKp1',\n", + " 'id': '6deiaArbeoqp1xPEGdEKp1',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b273de1af2785a83cc660155a0c4',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e02de1af2785a83cc660155a0c4',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00004851de1af2785a83cc660155a0c4',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'By the Way (Deluxe Edition)',\n", + " 'release_date': '2002-07-09',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 18,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:6deiaArbeoqp1xPEGdEKp1'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 216933,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USWB10201688'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/1f2V8U1BiWaC9aJWmpOARe'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/1f2V8U1BiWaC9aJWmpOARe',\n", + " 'id': '1f2V8U1BiWaC9aJWmpOARe',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'By the Way',\n", + " 'popularity': 79,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/9caddc9fdc2951fcdfe1f3fbda147c5d1871501b?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 1,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:1f2V8U1BiWaC9aJWmpOARe'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/43otFXrY0bgaq5fB3GrZj6'},\n", + " 'href': 'https://api.spotify.com/v1/albums/43otFXrY0bgaq5fB3GrZj6',\n", + " 'id': '43otFXrY0bgaq5fB3GrZj6',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b27358406b3f1ac3ceaff7a64fef',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e0258406b3f1ac3ceaff7a64fef',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000485158406b3f1ac3ceaff7a64fef',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'The Getaway',\n", + " 'release_date': '2016-06-17',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 13,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:43otFXrY0bgaq5fB3GrZj6'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 302000,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USWB11600478'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/2oaK4JLVnmRGIO9ytBE1bt'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/2oaK4JLVnmRGIO9ytBE1bt',\n", + " 'id': '2oaK4JLVnmRGIO9ytBE1bt',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Dark Necessities',\n", + " 'popularity': 76,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/b2ed4a9710ca0512ce58df1702f375f4ad2e4c13?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 2,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:2oaK4JLVnmRGIO9ytBE1bt'},\n", + " {'album': {'album_type': 'album',\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/30Perjew8HyGkdSmqguYyg'},\n", + " 'href': 'https://api.spotify.com/v1/albums/30Perjew8HyGkdSmqguYyg',\n", + " 'id': '30Perjew8HyGkdSmqguYyg',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b273153d79816d853f2694b2cc70',\n", + " 'width': 640},\n", + " {'height': 300,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e02153d79816d853f2694b2cc70',\n", + " 'width': 300},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/ab67616d00004851153d79816d853f2694b2cc70',\n", + " 'width': 64}],\n", + " 'is_playable': True,\n", + " 'name': 'Blood Sugar Sex Magik (Deluxe Edition)',\n", + " 'release_date': '1991-09-24',\n", + " 'release_date_precision': 'day',\n", + " 'total_tracks': 19,\n", + " 'type': 'album',\n", + " 'uri': 'spotify:album:30Perjew8HyGkdSmqguYyg'},\n", + " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", + " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", + " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", + " 'name': 'Red Hot Chili Peppers',\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", + " 'disc_number': 1,\n", + " 'duration_ms': 282906,\n", + " 'explicit': False,\n", + " 'external_ids': {'isrc': 'USWB19901574'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/0uppYCG86ajpV2hSR3dJJ0'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/0uppYCG86ajpV2hSR3dJJ0',\n", + " 'id': '0uppYCG86ajpV2hSR3dJJ0',\n", + " 'is_local': False,\n", + " 'is_playable': True,\n", + " 'name': 'Give It Away',\n", + " 'popularity': 76,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/e0c62e6fb378167d40ab941124f9ed7b9911a35e?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 9,\n", + " 'type': 'track',\n", + " 'uri': 'spotify:track:0uppYCG86ajpV2hSR3dJJ0'}]}" + ] + }, + "execution_count": 956, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "top_tracks_json = top_tracks_response.json()\n", + "top_tracks_json" + ] + }, + { + "cell_type": "code", + "execution_count": 957, + "id": "03760a1a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Under the Bridge',\n", + " 'Californication',\n", + " \"Can't Stop\",\n", + " 'Scar Tissue',\n", + " 'Otherside',\n", + " 'Snow (Hey Oh)',\n", + " 'Dani California',\n", + " 'By the Way',\n", + " 'Dark Necessities',\n", + " 'Give It Away']" + ] + }, + "execution_count": 957, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Top Tracks\n", + "[top_tracks_json['tracks'][i]['name'] for i in range(len(top_tracks_json['tracks']))]" + ] + }, + { + "cell_type": "code", + "execution_count": 958, + "id": "772e1d54", + "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", + "
idhrefnameuritracks
03d9DChrdc6BOeFsbrZ3Is0https://api.spotify.com/v1/tracks/3d9DChrdc6BO...Under the Bridgespotify:track:3d9DChrdc6BOeFsbrZ3Is00L8ExT028jH3ddEcZwqJJ5
148UPSzbZjgc449aqz8bxoxhttps://api.spotify.com/v1/tracks/48UPSzbZjgc4...Californicationspotify:track:48UPSzbZjgc449aqz8bxox0L8ExT028jH3ddEcZwqJJ5
23ZOEytgrvLwQaqXreDs2Jxhttps://api.spotify.com/v1/tracks/3ZOEytgrvLwQ...Can't Stopspotify:track:3ZOEytgrvLwQaqXreDs2Jx0L8ExT028jH3ddEcZwqJJ5
31G391cbiT3v3Cywg8T7DM1https://api.spotify.com/v1/tracks/1G391cbiT3v3...Scar Tissuespotify:track:1G391cbiT3v3Cywg8T7DM10L8ExT028jH3ddEcZwqJJ5
464BbK9SFKH2jk86U3dGj2Phttps://api.spotify.com/v1/tracks/64BbK9SFKH2j...Othersidespotify:track:64BbK9SFKH2jk86U3dGj2P0L8ExT028jH3ddEcZwqJJ5
52aibwv5hGXSgw7Yru8IYTOhttps://api.spotify.com/v1/tracks/2aibwv5hGXSg...Snow (Hey Oh)spotify:track:2aibwv5hGXSgw7Yru8IYTO0L8ExT028jH3ddEcZwqJJ5
610Nmj3JCNoMeBQ87uw5j8khttps://api.spotify.com/v1/tracks/10Nmj3JCNoMe...Dani Californiaspotify:track:10Nmj3JCNoMeBQ87uw5j8k0L8ExT028jH3ddEcZwqJJ5
71f2V8U1BiWaC9aJWmpOARehttps://api.spotify.com/v1/tracks/1f2V8U1BiWaC...By the Wayspotify:track:1f2V8U1BiWaC9aJWmpOARe0L8ExT028jH3ddEcZwqJJ5
82oaK4JLVnmRGIO9ytBE1bthttps://api.spotify.com/v1/tracks/2oaK4JLVnmRG...Dark Necessitiesspotify:track:2oaK4JLVnmRGIO9ytBE1bt0L8ExT028jH3ddEcZwqJJ5
90uppYCG86ajpV2hSR3dJJ0https://api.spotify.com/v1/tracks/0uppYCG86ajp...Give It Awayspotify:track:0uppYCG86ajpV2hSR3dJJ00L8ExT028jH3ddEcZwqJJ5
\n", + "
" + ], + "text/plain": [ + " id href \\\n", + "0 3d9DChrdc6BOeFsbrZ3Is0 https://api.spotify.com/v1/tracks/3d9DChrdc6BO... \n", + "1 48UPSzbZjgc449aqz8bxox https://api.spotify.com/v1/tracks/48UPSzbZjgc4... \n", + "2 3ZOEytgrvLwQaqXreDs2Jx https://api.spotify.com/v1/tracks/3ZOEytgrvLwQ... \n", + "3 1G391cbiT3v3Cywg8T7DM1 https://api.spotify.com/v1/tracks/1G391cbiT3v3... \n", + "4 64BbK9SFKH2jk86U3dGj2P https://api.spotify.com/v1/tracks/64BbK9SFKH2j... \n", + "5 2aibwv5hGXSgw7Yru8IYTO https://api.spotify.com/v1/tracks/2aibwv5hGXSg... \n", + "6 10Nmj3JCNoMeBQ87uw5j8k https://api.spotify.com/v1/tracks/10Nmj3JCNoMe... \n", + "7 1f2V8U1BiWaC9aJWmpOARe https://api.spotify.com/v1/tracks/1f2V8U1BiWaC... \n", + "8 2oaK4JLVnmRGIO9ytBE1bt https://api.spotify.com/v1/tracks/2oaK4JLVnmRG... \n", + "9 0uppYCG86ajpV2hSR3dJJ0 https://api.spotify.com/v1/tracks/0uppYCG86ajp... \n", + "\n", + " name uri \\\n", + "0 Under the Bridge spotify:track:3d9DChrdc6BOeFsbrZ3Is0 \n", + "1 Californication spotify:track:48UPSzbZjgc449aqz8bxox \n", + "2 Can't Stop spotify:track:3ZOEytgrvLwQaqXreDs2Jx \n", + "3 Scar Tissue spotify:track:1G391cbiT3v3Cywg8T7DM1 \n", + "4 Otherside spotify:track:64BbK9SFKH2jk86U3dGj2P \n", + "5 Snow (Hey Oh) spotify:track:2aibwv5hGXSgw7Yru8IYTO \n", + "6 Dani California spotify:track:10Nmj3JCNoMeBQ87uw5j8k \n", + "7 By the Way spotify:track:1f2V8U1BiWaC9aJWmpOARe \n", + "8 Dark Necessities spotify:track:2oaK4JLVnmRGIO9ytBE1bt \n", + "9 Give It Away spotify:track:0uppYCG86ajpV2hSR3dJJ0 \n", + "\n", + " tracks \n", + "0 0L8ExT028jH3ddEcZwqJJ5 \n", + "1 0L8ExT028jH3ddEcZwqJJ5 \n", + "2 0L8ExT028jH3ddEcZwqJJ5 \n", + "3 0L8ExT028jH3ddEcZwqJJ5 \n", + "4 0L8ExT028jH3ddEcZwqJJ5 \n", + "5 0L8ExT028jH3ddEcZwqJJ5 \n", + "6 0L8ExT028jH3ddEcZwqJJ5 \n", + "7 0L8ExT028jH3ddEcZwqJJ5 \n", + "8 0L8ExT028jH3ddEcZwqJJ5 \n", + "9 0L8ExT028jH3ddEcZwqJJ5 " + ] + }, + "execution_count": 958, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Create DataFrames\n", + "top_tracks_df = pd.DataFrame(top_tracks_json['tracks'])[['id','href','name','uri']]\n", + "top_tracks_df['tracks'] = artist_id\n", + "top_tracks_df" + ] + }, + { + "cell_type": "code", + "execution_count": 959, + "id": "5910eed8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index(['external_urls', 'followers', 'genres', 'href', 'id', 'images', 'name',\n", + " 'popularity', 'type', 'uri', 'artist_id'],\n", + " dtype='object')\n", + "Index(['id', 'href', 'name', 'uri', 'tracks'], dtype='object')\n" + ] + } + ], + "source": [ + "print(artist_df.columns)\n", + "print(top_tracks_df.columns)" + ] + }, + { + "cell_type": "markdown", + "id": "b0de1f10", + "metadata": {}, + "source": [ + "### 3. Related artists" + ] + }, + { + "cell_type": "code", + "execution_count": 944, + "id": "6f29a8d9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5/related-artists'" + ] + }, + "execution_count": 944, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Get Related artists\n", + "\n", + "method = '/related-artists'\n", "\n", - "full_endpoint = \n", + "full_endpoint = base_url + resource + parameters + method\n", "full_endpoint" ] }, + { + "cell_type": "code", + "execution_count": 945, + "id": "3c890e5e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 945, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "related_artists_response = requests.get(full_endpoint, headers = header_info)\n", + "related_artists_response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": 946, + "id": "516b044a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/7jy3rLJdDQY21OgRLCZ9sD'},\n", + " 'followers': {'href': None, 'total': 11362882},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'modern rock',\n", + " 'permanent wave',\n", + " 'post-grunge',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/7jy3rLJdDQY21OgRLCZ9sD',\n", + " 'id': '7jy3rLJdDQY21OgRLCZ9sD',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebc884df599abc793c116cdf15',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174c884df599abc793c116cdf15',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178c884df599abc793c116cdf15',\n", + " 'width': 160}],\n", + " 'name': 'Foo Fighters',\n", + " 'popularity': 75,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7jy3rLJdDQY21OgRLCZ9sD'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2d0hyoQ5ynDBnkvAbJKORj'},\n", + " 'followers': {'href': None, 'total': 5667457},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'conscious hip hop',\n", + " 'funk metal',\n", + " 'hard rock',\n", + " 'nu metal',\n", + " 'political hip hop',\n", + " 'post-grunge',\n", + " 'rap metal',\n", + " 'rap rock',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2d0hyoQ5ynDBnkvAbJKORj',\n", + " 'id': '2d0hyoQ5ynDBnkvAbJKORj',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebda4bd2b213cae330e2a4a901',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174da4bd2b213cae330e2a4a901',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178da4bd2b213cae330e2a4a901',\n", + " 'width': 160}],\n", + " 'name': 'Rage Against The Machine',\n", + " 'popularity': 68,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2d0hyoQ5ynDBnkvAbJKORj'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2ziB7fzrXBoh1HUPS6sVFn'},\n", + " 'followers': {'href': None, 'total': 4309698},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'grunge',\n", + " 'hard rock',\n", + " 'nu metal',\n", + " 'permanent wave',\n", + " 'post-grunge',\n", + " 'rock',\n", + " 'supergroup'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2ziB7fzrXBoh1HUPS6sVFn',\n", + " 'id': '2ziB7fzrXBoh1HUPS6sVFn',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb5a865295befda9e060a72cb0',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051745a865295befda9e060a72cb0',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1785a865295befda9e060a72cb0',\n", + " 'width': 160}],\n", + " 'name': 'Audioslave',\n", + " 'popularity': 65,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2ziB7fzrXBoh1HUPS6sVFn'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/1w5Kfo2jwwIPruYS2UWh56'},\n", + " 'followers': {'href': None, 'total': 8454993},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'grunge',\n", + " 'permanent wave',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/1w5Kfo2jwwIPruYS2UWh56',\n", + " 'id': '1w5Kfo2jwwIPruYS2UWh56',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb122d1145d880736383742ebc',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174122d1145d880736383742ebc',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178122d1145d880736383742ebc',\n", + " 'width': 160}],\n", + " 'name': 'Pearl Jam',\n", + " 'popularity': 71,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:1w5Kfo2jwwIPruYS2UWh56'},\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/6olE6TJLqED3rqDCT0FyPh'},\n", + " 'followers': {'href': None, 'total': 18411527},\n", + " 'genres': ['grunge', 'permanent wave', 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6olE6TJLqED3rqDCT0FyPh',\n", + " 'id': '6olE6TJLqED3rqDCT0FyPh',\n", + " 'images': [{'height': 1057,\n", + " 'url': 'https://i.scdn.co/image/84282c28d851a700132356381fcfbadc67ff498b',\n", + " 'width': 1000},\n", + " {'height': 677,\n", + " 'url': 'https://i.scdn.co/image/a4e10b79a642e9891383448cbf37d7266a6883d6',\n", + " 'width': 640},\n", + " {'height': 211,\n", + " 'url': 'https://i.scdn.co/image/42ae0f180f16e2f21c1f2212717fc436f5b95451',\n", + " 'width': 200},\n", + " {'height': 68,\n", + " 'url': 'https://i.scdn.co/image/e797ad36d56c3fc8fa06c6fe91263a15bf8391b8',\n", + " 'width': 64}],\n", + " 'name': 'Nirvana',\n", + " 'popularity': 78,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6olE6TJLqED3rqDCT0FyPh'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5xUf6j4upBrXZPg6AI4MRK'},\n", + " 'followers': {'href': None, 'total': 4173767},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'classic rock',\n", + " 'grunge',\n", + " 'hard rock',\n", + " 'nu metal',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/5xUf6j4upBrXZPg6AI4MRK',\n", + " 'id': '5xUf6j4upBrXZPg6AI4MRK',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebafa254b2a224584485286526',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174afa254b2a224584485286526',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178afa254b2a224584485286526',\n", + " 'width': 160}],\n", + " 'name': 'Soundgarden',\n", + " 'popularity': 64,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:5xUf6j4upBrXZPg6AI4MRK'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3YcBF2ttyueytpXtEzn1Za'},\n", + " 'followers': {'href': None, 'total': 3135573},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'funk metal',\n", + " 'funk rock',\n", + " 'nu metal',\n", + " 'post-grunge',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/3YcBF2ttyueytpXtEzn1Za',\n", + " 'id': '3YcBF2ttyueytpXtEzn1Za',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebbaebf3a81961bdf7173ab959',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174baebf3a81961bdf7173ab959',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178baebf3a81961bdf7173ab959',\n", + " 'width': 160}],\n", + " 'name': 'Incubus',\n", + " 'popularity': 66,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:3YcBF2ttyueytpXtEzn1Za'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5LfGQac0EIXyAN8aUwmNAQ'},\n", + " 'followers': {'href': None, 'total': 5233933},\n", + " 'genres': ['alternative metal',\n", + " 'permanent wave',\n", + " 'post-grunge',\n", + " 'punk',\n", + " 'rock',\n", + " 'skate punk',\n", + " 'socal pop punk'],\n", + " 'href': 'https://api.spotify.com/v1/artists/5LfGQac0EIXyAN8aUwmNAQ',\n", + " 'id': '5LfGQac0EIXyAN8aUwmNAQ',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebd7c5bbf32459922a72ec0d31',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174d7c5bbf32459922a72ec0d31',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178d7c5bbf32459922a72ec0d31',\n", + " 'width': 160}],\n", + " 'name': 'The Offspring',\n", + " 'popularity': 74,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:5LfGQac0EIXyAN8aUwmNAQ'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2UazAtjfzqBF0Nho2awK4z'},\n", + " 'followers': {'href': None, 'total': 3355895},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'classic rock',\n", + " 'grunge',\n", + " 'hard rock',\n", + " 'nu metal',\n", + " 'post-grunge',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2UazAtjfzqBF0Nho2awK4z',\n", + " 'id': '2UazAtjfzqBF0Nho2awK4z',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb4bb64f87db255d76538b905f',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051744bb64f87db255d76538b905f',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1784bb64f87db255d76538b905f',\n", + " 'width': 160}],\n", + " 'name': 'Stone Temple Pilots',\n", + " 'popularity': 64,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2UazAtjfzqBF0Nho2awK4z'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/64tNsm6TnZe2zpcMVMOoHL'},\n", + " 'followers': {'href': None, 'total': 4769618},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'grunge',\n", + " 'hard rock',\n", + " 'nu metal',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/64tNsm6TnZe2zpcMVMOoHL',\n", + " 'id': '64tNsm6TnZe2zpcMVMOoHL',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb6114a63659d0d5c0a801f733',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051746114a63659d0d5c0a801f733',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1786114a63659d0d5c0a801f733',\n", + " 'width': 160}],\n", + " 'name': 'Alice In Chains',\n", + " 'popularity': 69,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:64tNsm6TnZe2zpcMVMOoHL'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7oPftvlwr6VrsViSDV7fJY'},\n", + " 'followers': {'href': None, 'total': 14396087},\n", + " 'genres': ['modern rock', 'permanent wave', 'punk', 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/7oPftvlwr6VrsViSDV7fJY',\n", + " 'id': '7oPftvlwr6VrsViSDV7fJY',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb6ff0cd5ef2ecf733804984bb',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051746ff0cd5ef2ecf733804984bb',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1786ff0cd5ef2ecf733804984bb',\n", + " 'width': 160}],\n", + " 'name': 'Green Day',\n", + " 'popularity': 78,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7oPftvlwr6VrsViSDV7fJY'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/36QJpDe2go2KgaRleHCDTp'},\n", + " 'followers': {'href': None, 'total': 13832236},\n", + " 'genres': ['album rock', 'classic rock', 'hard rock', 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/36QJpDe2go2KgaRleHCDTp',\n", + " 'id': '36QJpDe2go2KgaRleHCDTp',\n", + " 'images': [{'height': 600,\n", + " 'url': 'https://i.scdn.co/image/207803ce008388d3427a685254f9de6a8f61dc2e',\n", + " 'width': 600},\n", + " {'height': 200,\n", + " 'url': 'https://i.scdn.co/image/b0248a44865493e6a03832aa89854ada16ff07a8',\n", + " 'width': 200},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/16eb3cdae0d824b520ac17710e943a99d3ef6602',\n", + " 'width': 64}],\n", + " 'name': 'Led Zeppelin',\n", + " 'popularity': 73,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:36QJpDe2go2KgaRleHCDTp'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5eAWCfyUhZtHHtBdNk56l1'},\n", + " 'followers': {'href': None, 'total': 9753467},\n", + " 'genres': ['alternative metal', 'nu metal', 'rap metal', 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/5eAWCfyUhZtHHtBdNk56l1',\n", + " 'id': '5eAWCfyUhZtHHtBdNk56l1',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb60063d3451ade8f9fab397c2',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000517460063d3451ade8f9fab397c2',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f17860063d3451ade8f9fab397c2',\n", + " 'width': 160}],\n", + " 'name': 'System Of A Down',\n", + " 'popularity': 76,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:5eAWCfyUhZtHHtBdNk56l1'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/776Uo845nYHJpNaStv1Ds4'},\n", + " 'followers': {'href': None, 'total': 6413265},\n", + " 'genres': ['acid rock',\n", + " 'album rock',\n", + " 'alternative rock',\n", + " 'classic rock',\n", + " 'hard rock',\n", + " 'proto-metal',\n", + " 'psychedelic rock',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/776Uo845nYHJpNaStv1Ds4',\n", + " 'id': '776Uo845nYHJpNaStv1Ds4',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb31f6ab67e6025de876475814',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000517431f6ab67e6025de876475814',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f17831f6ab67e6025de876475814',\n", + " 'width': 160}],\n", + " 'name': 'Jimi Hendrix',\n", + " 'popularity': 67,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:776Uo845nYHJpNaStv1Ds4'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/4pejUc4iciQfgdX6OKulQn'},\n", + " 'followers': {'href': None, 'total': 3366471},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'grunge',\n", + " 'modern rock',\n", + " 'nu metal',\n", + " 'palm desert scene',\n", + " 'rock',\n", + " 'stoner metal',\n", + " 'stoner rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/4pejUc4iciQfgdX6OKulQn',\n", + " 'id': '4pejUc4iciQfgdX6OKulQn',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb909b2c4b7c768ee03445cd10',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174909b2c4b7c768ee03445cd10',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178909b2c4b7c768ee03445cd10',\n", + " 'width': 160}],\n", + " 'name': 'Queens of the Stone Age',\n", + " 'popularity': 68,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:4pejUc4iciQfgdX6OKulQn'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6FBDaR13swtiWwGhX1WQsP'},\n", + " 'followers': {'href': None, 'total': 7875556},\n", + " 'genres': ['alternative metal',\n", + " 'modern rock',\n", + " 'pop punk',\n", + " 'punk',\n", + " 'rock',\n", + " 'socal pop punk'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6FBDaR13swtiWwGhX1WQsP',\n", + " 'id': '6FBDaR13swtiWwGhX1WQsP',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb5da36f8b98dd965336a1507a',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051745da36f8b98dd965336a1507a',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1785da36f8b98dd965336a1507a',\n", + " 'width': 160}],\n", + " 'name': 'blink-182',\n", + " 'popularity': 79,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6FBDaR13swtiWwGhX1WQsP'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/4F84IBURUo98rz4r61KF70'},\n", + " 'followers': {'href': None, 'total': 2934930},\n", + " 'genres': ['alternative rock',\n", + " 'blues rock',\n", + " 'detroit rock',\n", + " 'garage rock',\n", + " 'modern blues rock',\n", + " 'permanent wave',\n", + " 'punk blues',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/4F84IBURUo98rz4r61KF70',\n", + " 'id': '4F84IBURUo98rz4r61KF70',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb70cc06de8fc28226d4743cd9',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000517470cc06de8fc28226d4743cd9',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f17870cc06de8fc28226d4743cd9',\n", + " 'width': 160}],\n", + " 'name': 'The White Stripes',\n", + " 'popularity': 68,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:4F84IBURUo98rz4r61KF70'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/165ZgPlLkK7bf5bDoFc6Sb'},\n", + " 'followers': {'href': None, 'total': 5422528},\n", + " 'genres': ['alternative metal',\n", + " 'funk metal',\n", + " 'nu metal',\n", + " 'post-grunge',\n", + " 'rap metal',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/165ZgPlLkK7bf5bDoFc6Sb',\n", + " 'id': '165ZgPlLkK7bf5bDoFc6Sb',\n", + " 'images': [{'height': 1006,\n", + " 'url': 'https://i.scdn.co/image/4654955890cb62a6abe9daadfd2b3ecdee8036e4',\n", + " 'width': 1000},\n", + " {'height': 644,\n", + " 'url': 'https://i.scdn.co/image/c8e241c3b7ddb2839be99acf9a1ad2d73f04b936',\n", + " 'width': 640},\n", + " {'height': 201,\n", + " 'url': 'https://i.scdn.co/image/38532b2db9bc627567271da917855a59be788860',\n", + " 'width': 200},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/67ab66b1154c3115005086d60853fc954717a2ea',\n", + " 'width': 64}],\n", + " 'name': 'Limp Bizkit',\n", + " 'popularity': 72,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:165ZgPlLkK7bf5bDoFc6Sb'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7Ey4PD4MYsKc5I2dolUwbH'},\n", + " 'followers': {'href': None, 'total': 13882544},\n", + " 'genres': ['album rock', 'classic rock', 'hard rock', 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/7Ey4PD4MYsKc5I2dolUwbH',\n", + " 'id': '7Ey4PD4MYsKc5I2dolUwbH',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebc5733401b4689b2064458e7d',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174c5733401b4689b2064458e7d',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178c5733401b4689b2064458e7d',\n", + " 'width': 160}],\n", + " 'name': 'Aerosmith',\n", + " 'popularity': 73,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7Ey4PD4MYsKc5I2dolUwbH'}]}" + ] + }, + "execution_count": 946, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "related_artists_json = related_artists_response.json()\n", + "related_artists_json" + ] + }, + { + "cell_type": "code", + "execution_count": 947, + "id": "fdcd1b96", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['Foo Fighters',\n", + " 'Rage Against The Machine',\n", + " 'Audioslave',\n", + " 'Pearl Jam',\n", + " 'The Smashing Pumpkins',\n", + " 'Nirvana',\n", + " 'Soundgarden',\n", + " 'Incubus',\n", + " 'The Offspring',\n", + " 'Stone Temple Pilots',\n", + " 'Alice In Chains',\n", + " 'Green Day',\n", + " 'Led Zeppelin',\n", + " 'System Of A Down',\n", + " 'Jimi Hendrix',\n", + " 'Queens of the Stone Age',\n", + " 'blink-182',\n", + " 'The White Stripes',\n", + " 'Limp Bizkit',\n", + " 'Aerosmith']" + ] + }, + "execution_count": 947, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Related Artists\n", + "[related_artists_json['artists'][i]['name'] for i in range(len(related_artists_json['artists']))]" + ] + }, + { + "cell_type": "code", + "execution_count": 960, + "id": "b6faa31a", + "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", + "
idnamegenrespopularityfollowers
07jy3rLJdDQY21OgRLCZ9sDFoo Fighters[alternative metal, alternative rock, modern r...75{'href': None, 'total': 11362882}
12d0hyoQ5ynDBnkvAbJKORjRage Against The Machine[alternative metal, alternative rock, consciou...68{'href': None, 'total': 5667457}
22ziB7fzrXBoh1HUPS6sVFnAudioslave[alternative metal, alternative rock, grunge, ...65{'href': None, 'total': 4309698}
31w5Kfo2jwwIPruYS2UWh56Pearl Jam[alternative metal, alternative rock, grunge, ...71{'href': None, 'total': 8454993}
440Yq4vzPs9VNUrIBG5Jr2iThe Smashing Pumpkins[alternative metal, alternative rock, grunge, ...70{'href': None, 'total': 4760553}
\n", + "
" + ], + "text/plain": [ + " id name \\\n", + "0 7jy3rLJdDQY21OgRLCZ9sD Foo Fighters \n", + "1 2d0hyoQ5ynDBnkvAbJKORj Rage Against The Machine \n", + "2 2ziB7fzrXBoh1HUPS6sVFn Audioslave \n", + "3 1w5Kfo2jwwIPruYS2UWh56 Pearl Jam \n", + "4 40Yq4vzPs9VNUrIBG5Jr2i The Smashing Pumpkins \n", + "\n", + " genres popularity \\\n", + "0 [alternative metal, alternative rock, modern r... 75 \n", + "1 [alternative metal, alternative rock, consciou... 68 \n", + "2 [alternative metal, alternative rock, grunge, ... 65 \n", + "3 [alternative metal, alternative rock, grunge, ... 71 \n", + "4 [alternative metal, alternative rock, grunge, ... 70 \n", + "\n", + " followers \n", + "0 {'href': None, 'total': 11362882} \n", + "1 {'href': None, 'total': 5667457} \n", + "2 {'href': None, 'total': 4309698} \n", + "3 {'href': None, 'total': 8454993} \n", + "4 {'href': None, 'total': 4760553} " + ] + }, + "execution_count": 960, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Create DataFrames\n", + "related_artists_df = pd.DataFrame(related_artists_json['artists'])[['id','name','genres','popularity','followers']]\n", + "related_artists_df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 961, + "id": "76fd9618", + "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", + "
related_idrelated_namerelated_genrespopularityrelated_followers
07jy3rLJdDQY21OgRLCZ9sDFoo Fighters[alternative metal, alternative rock, modern r...75{'href': None, 'total': 11362882}
12d0hyoQ5ynDBnkvAbJKORjRage Against The Machine[alternative metal, alternative rock, consciou...68{'href': None, 'total': 5667457}
22ziB7fzrXBoh1HUPS6sVFnAudioslave[alternative metal, alternative rock, grunge, ...65{'href': None, 'total': 4309698}
31w5Kfo2jwwIPruYS2UWh56Pearl Jam[alternative metal, alternative rock, grunge, ...71{'href': None, 'total': 8454993}
440Yq4vzPs9VNUrIBG5Jr2iThe Smashing Pumpkins[alternative metal, alternative rock, grunge, ...70{'href': None, 'total': 4760553}
\n", + "
" + ], + "text/plain": [ + " related_id related_name \\\n", + "0 7jy3rLJdDQY21OgRLCZ9sD Foo Fighters \n", + "1 2d0hyoQ5ynDBnkvAbJKORj Rage Against The Machine \n", + "2 2ziB7fzrXBoh1HUPS6sVFn Audioslave \n", + "3 1w5Kfo2jwwIPruYS2UWh56 Pearl Jam \n", + "4 40Yq4vzPs9VNUrIBG5Jr2i The Smashing Pumpkins \n", + "\n", + " related_genres popularity \\\n", + "0 [alternative metal, alternative rock, modern r... 75 \n", + "1 [alternative metal, alternative rock, consciou... 68 \n", + "2 [alternative metal, alternative rock, grunge, ... 65 \n", + "3 [alternative metal, alternative rock, grunge, ... 71 \n", + "4 [alternative metal, alternative rock, grunge, ... 70 \n", + "\n", + " related_followers \n", + "0 {'href': None, 'total': 11362882} \n", + "1 {'href': None, 'total': 5667457} \n", + "2 {'href': None, 'total': 4309698} \n", + "3 {'href': None, 'total': 8454993} \n", + "4 {'href': None, 'total': 4760553} " + ] + }, + "execution_count": 961, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Rename columns\n", + "related_artists_df = related_artists_df.rename(columns={'id':'related_id',\n", + " 'name':'related_name',\n", + " 'genres':'related_genres',\n", + " 'popularity': 'popularity',\n", + " 'followers':'related_followers'\n", + " })\n", + "related_artists_df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 962, + "id": "8d1f3639", + "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", + "
related_idrelated_namerelated_genrespopularityrelated_followersartist_id
07jy3rLJdDQY21OgRLCZ9sDFoo Fighters[alternative metal, alternative rock, modern r...75{'href': None, 'total': 11362882}0L8ExT028jH3ddEcZwqJJ5
12d0hyoQ5ynDBnkvAbJKORjRage Against The Machine[alternative metal, alternative rock, consciou...68{'href': None, 'total': 5667457}0L8ExT028jH3ddEcZwqJJ5
22ziB7fzrXBoh1HUPS6sVFnAudioslave[alternative metal, alternative rock, grunge, ...65{'href': None, 'total': 4309698}0L8ExT028jH3ddEcZwqJJ5
31w5Kfo2jwwIPruYS2UWh56Pearl Jam[alternative metal, alternative rock, grunge, ...71{'href': None, 'total': 8454993}0L8ExT028jH3ddEcZwqJJ5
440Yq4vzPs9VNUrIBG5Jr2iThe Smashing Pumpkins[alternative metal, alternative rock, grunge, ...70{'href': None, 'total': 4760553}0L8ExT028jH3ddEcZwqJJ5
\n", + "
" + ], + "text/plain": [ + " related_id related_name \\\n", + "0 7jy3rLJdDQY21OgRLCZ9sD Foo Fighters \n", + "1 2d0hyoQ5ynDBnkvAbJKORj Rage Against The Machine \n", + "2 2ziB7fzrXBoh1HUPS6sVFn Audioslave \n", + "3 1w5Kfo2jwwIPruYS2UWh56 Pearl Jam \n", + "4 40Yq4vzPs9VNUrIBG5Jr2i The Smashing Pumpkins \n", + "\n", + " related_genres popularity \\\n", + "0 [alternative metal, alternative rock, modern r... 75 \n", + "1 [alternative metal, alternative rock, consciou... 68 \n", + "2 [alternative metal, alternative rock, grunge, ... 65 \n", + "3 [alternative metal, alternative rock, grunge, ... 71 \n", + "4 [alternative metal, alternative rock, grunge, ... 70 \n", + "\n", + " related_followers artist_id \n", + "0 {'href': None, 'total': 11362882} 0L8ExT028jH3ddEcZwqJJ5 \n", + "1 {'href': None, 'total': 5667457} 0L8ExT028jH3ddEcZwqJJ5 \n", + "2 {'href': None, 'total': 4309698} 0L8ExT028jH3ddEcZwqJJ5 \n", + "3 {'href': None, 'total': 8454993} 0L8ExT028jH3ddEcZwqJJ5 \n", + "4 {'href': None, 'total': 4760553} 0L8ExT028jH3ddEcZwqJJ5 " + ] + }, + "execution_count": 962, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Add a column with selected id artist\n", + "related_artists_df['artist_id'] = artist_id\n", + "related_artists_df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 965, + "id": "0451ecf4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index(['related_id', 'related_name', 'related_genres', 'popularity',\n", + " 'related_followers', 'artist_id'],\n", + " dtype='object')\n", + "Index(['external_urls', 'followers', 'genres', 'href', 'id', 'images', 'name',\n", + " 'popularity', 'type', 'uri', 'artist_id'],\n", + " dtype='object')\n", + "Index(['id', 'href', 'name', 'uri', 'tracks'], dtype='object')\n" + ] + } + ], + "source": [ + "print(related_artists_df.columns)\n", + "print(artist_df.columns)\n", + "print(top_tracks_df.columns)" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "50ec3959", + "id": "dadd9205", "metadata": {}, "outputs": [], "source": [ - "# Start building your playlist!!!\n", + "# Join artist and related artist to merge info\n", "\n", - "\n" + "# For loop de mi artista con los top tracks, teniendo el id_artist de los related\n", + "# Crear una lista de los ids los related\n", + "\n", + "# Los 20 top tracks de los 10 arti\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "74dabeaf", + "metadata": {}, + "outputs": [], + "source": [ + "related_artists_df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 967, + "id": "3ae8c65e", + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'related_id'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_14984\\2131523432.py\u001b[0m in \u001b[0;36m?\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mplaylist_df\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmerge\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrelated_artists_df\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtop_tracks_df\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mon\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'related_id'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mplaylist_df\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\site-packages\\pandas\\core\\reshape\\merge.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)\u001b[0m\n\u001b[0;32m 144\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mbool\u001b[0m \u001b[1;33m|\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 145\u001b[0m \u001b[0mindicator\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[1;33m|\u001b[0m \u001b[0mbool\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 146\u001b[0m \u001b[0mvalidate\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[1;33m|\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 147\u001b[0m ) -> DataFrame:\n\u001b[1;32m--> 148\u001b[1;33m op = _MergeOperation(\n\u001b[0m\u001b[0;32m 149\u001b[0m \u001b[0mleft\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 150\u001b[0m \u001b[0mright\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 151\u001b[0m \u001b[0mhow\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mhow\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\site-packages\\pandas\\core\\reshape\\merge.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(self, left, right, how, on, left_on, right_on, axis, left_index, right_index, sort, suffixes, indicator, validate)\u001b[0m\n\u001b[0;32m 733\u001b[0m (\n\u001b[0;32m 734\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mleft_join_keys\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 735\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mright_join_keys\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 736\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjoin_names\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 737\u001b[1;33m ) = self._get_merge_keys()\n\u001b[0m\u001b[0;32m 738\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 739\u001b[0m \u001b[1;31m# validate the merge keys dtypes. We may need to coerce\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 740\u001b[0m \u001b[1;31m# to avoid incompatible dtypes\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\site-packages\\pandas\\core\\reshape\\merge.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1199\u001b[0m \u001b[1;31m# Then we're either Hashable or a wrong-length arraylike,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1200\u001b[0m \u001b[1;31m# the latter of which will raise\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1201\u001b[0m \u001b[0mrk\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcast\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mHashable\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrk\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1202\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mrk\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1203\u001b[1;33m \u001b[0mright_keys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mright\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_label_or_level_values\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrk\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1204\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1205\u001b[0m \u001b[1;31m# work-around for merge_asof(right_index=True)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1206\u001b[0m \u001b[0mright_keys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mright\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m 1774\u001b[0m \u001b[0mvalues\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mxs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mother_axes\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_values\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1775\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_is_level_reference\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1776\u001b[0m \u001b[0mvalues\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maxes\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_level_values\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_values\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1777\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1778\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1779\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1780\u001b[0m \u001b[1;31m# Check for duplicates\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1781\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mvalues\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mKeyError\u001b[0m: 'related_id'" + ] + } + ], + "source": [ + "playlist_df = pd.merge(related_artists_df, top_tracks_df, on='related_id')\n", + "playlist_df" + ] + }, + { + "cell_type": "markdown", + "id": "87f28353", + "metadata": {}, + "source": [ + "# Checkpoint" ] }, { @@ -209,21 +2226,13 @@ "\n", "![I quit](https://media.giphy.com/media/3oFzlXPvXYZ4q8VQOs/giphy.gif)" ] - }, - { - "cell_type": "markdown", - "id": "0a399ce8", - "metadata": {}, - "source": [ - "---" - ] } ], "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 +2244,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.11" + "version": "3.10.13" } }, "nbformat": 4, From eb56d287f631d87b5a6888835bd0f7ec41dcef29 Mon Sep 17 00:00:00 2001 From: Andrew Bavuels Date: Mon, 13 Nov 2023 12:25:45 +0100 Subject: [PATCH 2/2] No ha sido la mejor entrega que he hecho :( --- notebooks/spotify_rest_api_challenge.ipynb | 2334 ++++++++++++++------ 1 file changed, 1617 insertions(+), 717 deletions(-) diff --git a/notebooks/spotify_rest_api_challenge.ipynb b/notebooks/spotify_rest_api_challenge.ipynb index 169e30b..1f6899e 100644 --- a/notebooks/spotify_rest_api_challenge.ipynb +++ b/notebooks/spotify_rest_api_challenge.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 923, + "execution_count": 33, "id": "17a49776", "metadata": {}, "outputs": [], @@ -39,21 +39,21 @@ }, { "cell_type": "code", - "execution_count": 924, + "execution_count": 34, "id": "7b5d2e52", "metadata": {}, "outputs": [], "source": [ "# Generate token with a POST request\n", "\n", - "client_id = 'bec9dd918ed04aca96b6eb3c699e443f'# CLIENT ID\n", - "client_secret = 'aafa5d5b0a44425b80336b4e57688b9c'# CLIENT SECRET\n", + "client_id = # CLIENT ID\n", + "client_secret = # CLIENT SECRET\n", "auth_url = 'https://accounts.spotify.com/api/token'" ] }, { "cell_type": "code", - "execution_count": 925, + "execution_count": 35, "id": "c7901d1e", "metadata": {}, "outputs": [], @@ -65,21 +65,20 @@ }, { "cell_type": "code", - "execution_count": 926, + "execution_count": 1, "id": "262e7e18", "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "{'access_token': 'BQD0ZISBlKm0lyo5kc_v4hEF7aGhjlx8--YMWnly2Qm2Zzr5RLjfw1ElRBOdT9p-gh6FAEqSW7SaE5gGHHSoYQpzaSPsZbo3HREpddsO5BdmpoStWnQ',\n", - " 'token_type': 'Bearer',\n", - " 'expires_in': 3600}" - ] - }, - "execution_count": 926, - "metadata": {}, - "output_type": "execute_result" + "ename": "NameError", + "evalue": "name 'auth_response' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m access_token \u001b[38;5;241m=\u001b[39m \u001b[43mauth_response\u001b[49m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124maccess_token\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m 2\u001b[0m auth_response\n", + "\u001b[1;31mNameError\u001b[0m: name 'auth_response' is not defined" + ] } ], "source": [ @@ -99,7 +98,7 @@ }, { "cell_type": "code", - "execution_count": 927, + "execution_count": 37, "id": "62e6d4fb", "metadata": {}, "outputs": [], @@ -112,19 +111,20 @@ }, { "cell_type": "code", - "execution_count": 928, + "execution_count": 2, "id": "a293e6e7", "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "{'Authorization': 'Bearer BQD0ZISBlKm0lyo5kc_v4hEF7aGhjlx8--YMWnly2Qm2Zzr5RLjfw1ElRBOdT9p-gh6FAEqSW7SaE5gGHHSoYQpzaSPsZbo3HREpddsO5BdmpoStWnQ'}" - ] - }, - "execution_count": 928, - "metadata": {}, - "output_type": "execute_result" + "ename": "NameError", + "evalue": "name 'header_info' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[2], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mheader_info\u001b[49m\n", + "\u001b[1;31mNameError\u001b[0m: name 'header_info' is not defined" + ] } ], "source": [ @@ -174,6 +174,14 @@ "---" ] }, + { + "cell_type": "markdown", + "id": "7e14c0df", + "metadata": {}, + "source": [ + "# Borrador" + ] + }, { "cell_type": "markdown", "id": "69fd5c14", @@ -188,18 +196,26 @@ }, { "cell_type": "code", - "execution_count": 929, - "id": "51426ff7", + "execution_count": 39, + "id": "d54ece25", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "https://api.spotify.com/v1/\n" + ] + } + ], "source": [ - "artist_id = '0L8ExT028jH3ddEcZwqJJ5'" + "print(base_url)" ] }, { "cell_type": "code", - "execution_count": 930, - "id": "4cab465e", + "execution_count": 22, + "id": "7ae72cfb", "metadata": {}, "outputs": [ { @@ -211,18 +227,18 @@ } ], "source": [ - "# Build the url for API call:\n", - "resource = 'artists' # Viene de la documentación\n", - "parameters = f'/{artist_id}'\n", + "artist_id = '0L8ExT028jH3ddEcZwqJJ5'\n", + "resource = 'artists/'\n", "\n", - "url = base_url + resource + parameters\n", - "print(url)" + "# Artist endpoint\n", + "artist_ep = base_url + resource + artist_id\n", + "print(artist_ep)" ] }, { "cell_type": "code", - "execution_count": 931, - "id": "4830ee02", + "execution_count": 23, + "id": "abb5e6d2", "metadata": {}, "outputs": [ { @@ -231,28 +247,28 @@ "200" ] }, - "execution_count": 931, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# API call\n", - "artist_response = requests.get(url, headers=header_info)\n", + "artist_response = requests.get(artist_ep, headers=header_info)\n", "artist_response.status_code" ] }, { "cell_type": "code", - "execution_count": 932, - "id": "c64da635", + "execution_count": 24, + "id": "2b230721", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", - " 'followers': {'href': None, 'total': 20243794},\n", + " 'followers': {'href': None, 'total': 20275607},\n", " 'genres': ['alternative rock',\n", " 'funk metal',\n", " 'funk rock',\n", @@ -275,22 +291,37 @@ " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}" ] }, - "execution_count": 932, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "artist_json = artist_response.json()\n", - "artist_json" + "artist_response = artist_response.json()\n", + "artist_response" + ] + }, + { + "cell_type": "markdown", + "id": "a47636b0", + "metadata": {}, + "source": [ + "### 2. Artist top tracks" ] }, { "cell_type": "code", - "execution_count": 933, - "id": "dd4e105c", + "execution_count": 25, + "id": "cf77327e", "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Artist DataFrame:\n" + ] + }, { "data": { "text/html": [ @@ -312,152 +343,62 @@ " \n", " \n", " \n", - " external_urls\n", - " followers\n", - " genres\n", - " href\n", " id\n", - " images\n", + " href\n", " name\n", - " popularity\n", - " type\n", " uri\n", - " artist_id\n", + " artist_name\n", " \n", " \n", " \n", " \n", " 0\n", - " {'spotify': 'https://open.spotify.com/artist/0...\n", - " {'href': None, 'total': 20243794}\n", - " [alternative rock, funk metal, funk rock, perm...\n", - " https://api.spotify.com/v1/artists/0L8ExT028jH...\n", " 0L8ExT028jH3ddEcZwqJJ5\n", - " [{'height': 640, 'url': 'https://i.scdn.co/ima...\n", + " https://open.spotify.com/artist/0L8ExT028jH3dd...\n", " Red Hot Chili Peppers\n", - " 80\n", - " artist\n", " spotify:artist:0L8ExT028jH3ddEcZwqJJ5\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", + " Red Hot Chili Peppers\n", " \n", " \n", "\n", "" ], "text/plain": [ - " external_urls \\\n", - "0 {'spotify': 'https://open.spotify.com/artist/0... \n", - "\n", - " followers \\\n", - "0 {'href': None, 'total': 20243794} \n", - "\n", - " genres \\\n", - "0 [alternative rock, funk metal, funk rock, perm... \n", - "\n", - " href id \\\n", - "0 https://api.spotify.com/v1/artists/0L8ExT028jH... 0L8ExT028jH3ddEcZwqJJ5 \n", - "\n", - " images name \\\n", - "0 [{'height': 640, 'url': 'https://i.scdn.co/ima... Red Hot Chili Peppers \n", + " id href \\\n", + "0 0L8ExT028jH3ddEcZwqJJ5 https://open.spotify.com/artist/0L8ExT028jH3dd... \n", "\n", - " popularity type uri \\\n", - "0 80 artist spotify:artist:0L8ExT028jH3ddEcZwqJJ5 \n", + " name uri \\\n", + "0 Red Hot Chili Peppers spotify:artist:0L8ExT028jH3ddEcZwqJJ5 \n", "\n", - " artist_id \n", - "0 0L8ExT028jH3ddEcZwqJJ5 " + " artist_name \n", + "0 Red Hot Chili Peppers " ] }, - "execution_count": 933, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# Create DataFrames\n", - "artist_df = pd.DataFrame([artist_json])\n", - "artist_df['artist_id'] = artist_id\n", + "# Getting the chosen artist top tracks\n", + "artist_data = {\n", + " \"id\": artist_response[\"id\"],\n", + " \"href\": artist_response[\"external_urls\"][\"spotify\"],\n", + " \"name\": artist_response[\"name\"],\n", + " \"uri\": artist_response[\"uri\"],\n", + " \"artist_name\": artist_response[\"name\"]\n", + "}\n", + "artist_df = pd.DataFrame([artist_data])\n", + "\n", + "# Display artist DataFrame\n", + "print(\"Artist DataFrame:\")\n", "artist_df" ] }, { "cell_type": "code", - "execution_count": 953, - "id": "f5966220", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Index(['external_urls', 'followers', 'genres', 'href', 'id', 'images', 'name',\n", - " 'popularity', 'type', 'uri', 'artist_id'],\n", - " dtype='object')\n" - ] - } - ], - "source": [ - "print(artist_df.columns)" - ] - }, - { - "cell_type": "markdown", - "id": "11cbe450", - "metadata": {}, - "source": [ - "### 2. Top-tracks" - ] - }, - { - "cell_type": "code", - "execution_count": 954, - "id": "a1854027", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5/top-tracks?market=ES'" - ] - }, - "execution_count": 954, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Get top tracks\n", - "method = '/top-tracks'\n", - "argument = '?market=ES'\n", - "full_endpoint = base_url + resource + parameters + method + argument\n", - "full_endpoint" - ] - }, - { - "cell_type": "code", - "execution_count": 955, - "id": "6ffbf563", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "200" - ] - }, - "execution_count": 955, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "top_tracks_response = requests.get(full_endpoint, headers = header_info)\n", - "top_tracks_response.status_code" - ] - }, - { - "cell_type": "code", - "execution_count": 956, - "id": "050efac3", + "execution_count": 29, + "id": "03583915", "metadata": {}, "outputs": [ { @@ -552,7 +493,7 @@ " 'is_local': False,\n", " 'is_playable': True,\n", " 'name': 'Californication',\n", - " 'popularity': 86,\n", + " 'popularity': 87,\n", " 'preview_url': 'https://p.scdn.co/mp3-preview/0fd595c5b63db10f4a99683f8248ea5d13700683?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", " 'track_number': 6,\n", " 'type': 'track',\n", @@ -693,7 +634,7 @@ " 'is_local': False,\n", " 'is_playable': True,\n", " 'name': 'Otherside',\n", - " 'popularity': 83,\n", + " 'popularity': 84,\n", " 'preview_url': 'https://p.scdn.co/mp3-preview/90076510970ced8308b85cd65776f75b99d97e7f?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", " 'track_number': 4,\n", " 'type': 'track',\n", @@ -740,7 +681,7 @@ " 'is_local': False,\n", " 'is_playable': True,\n", " 'name': 'Snow (Hey Oh)',\n", - " 'popularity': 81,\n", + " 'popularity': 82,\n", " 'preview_url': 'https://p.scdn.co/mp3-preview/d1e419a7f2aa9ba761be88802dbd3560b8f99776?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", " 'track_number': 2,\n", " 'type': 'track',\n", @@ -787,7 +728,7 @@ " 'is_local': False,\n", " 'is_playable': True,\n", " 'name': 'Dani California',\n", - " 'popularity': 80,\n", + " 'popularity': 81,\n", " 'preview_url': 'https://p.scdn.co/mp3-preview/0454b7cef05f7db734eb04bd4f3948009838f380?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", " 'track_number': 1,\n", " 'type': 'track',\n", @@ -846,25 +787,25 @@ " 'name': 'Red Hot Chili Peppers',\n", " 'type': 'artist',\n", " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", - " 'external_urls': {'spotify': 'https://open.spotify.com/album/43otFXrY0bgaq5fB3GrZj6'},\n", - " 'href': 'https://api.spotify.com/v1/albums/43otFXrY0bgaq5fB3GrZj6',\n", - " 'id': '43otFXrY0bgaq5fB3GrZj6',\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/30Perjew8HyGkdSmqguYyg'},\n", + " 'href': 'https://api.spotify.com/v1/albums/30Perjew8HyGkdSmqguYyg',\n", + " 'id': '30Perjew8HyGkdSmqguYyg',\n", " 'images': [{'height': 640,\n", - " 'url': 'https://i.scdn.co/image/ab67616d0000b27358406b3f1ac3ceaff7a64fef',\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b273153d79816d853f2694b2cc70',\n", " 'width': 640},\n", " {'height': 300,\n", - " 'url': 'https://i.scdn.co/image/ab67616d00001e0258406b3f1ac3ceaff7a64fef',\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e02153d79816d853f2694b2cc70',\n", " 'width': 300},\n", " {'height': 64,\n", - " 'url': 'https://i.scdn.co/image/ab67616d0000485158406b3f1ac3ceaff7a64fef',\n", + " 'url': 'https://i.scdn.co/image/ab67616d00004851153d79816d853f2694b2cc70',\n", " 'width': 64}],\n", " 'is_playable': True,\n", - " 'name': 'The Getaway',\n", - " 'release_date': '2016-06-17',\n", + " 'name': 'Blood Sugar Sex Magik (Deluxe Edition)',\n", + " 'release_date': '1991-09-24',\n", " 'release_date_precision': 'day',\n", - " 'total_tracks': 13,\n", + " 'total_tracks': 19,\n", " 'type': 'album',\n", - " 'uri': 'spotify:album:43otFXrY0bgaq5fB3GrZj6'},\n", + " 'uri': 'spotify:album:30Perjew8HyGkdSmqguYyg'},\n", " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", @@ -872,20 +813,20 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", " 'disc_number': 1,\n", - " 'duration_ms': 302000,\n", + " 'duration_ms': 282906,\n", " 'explicit': False,\n", - " 'external_ids': {'isrc': 'USWB11600478'},\n", - " 'external_urls': {'spotify': 'https://open.spotify.com/track/2oaK4JLVnmRGIO9ytBE1bt'},\n", - " 'href': 'https://api.spotify.com/v1/tracks/2oaK4JLVnmRGIO9ytBE1bt',\n", - " 'id': '2oaK4JLVnmRGIO9ytBE1bt',\n", + " 'external_ids': {'isrc': 'USWB19901574'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/0uppYCG86ajpV2hSR3dJJ0'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/0uppYCG86ajpV2hSR3dJJ0',\n", + " 'id': '0uppYCG86ajpV2hSR3dJJ0',\n", " 'is_local': False,\n", " 'is_playable': True,\n", - " 'name': 'Dark Necessities',\n", - " 'popularity': 76,\n", - " 'preview_url': 'https://p.scdn.co/mp3-preview/b2ed4a9710ca0512ce58df1702f375f4ad2e4c13?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", - " 'track_number': 2,\n", + " 'name': 'Give It Away',\n", + " 'popularity': 77,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/e0c62e6fb378167d40ab941124f9ed7b9911a35e?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 9,\n", " 'type': 'track',\n", - " 'uri': 'spotify:track:2oaK4JLVnmRGIO9ytBE1bt'},\n", + " 'uri': 'spotify:track:0uppYCG86ajpV2hSR3dJJ0'},\n", " {'album': {'album_type': 'album',\n", " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", @@ -893,25 +834,25 @@ " 'name': 'Red Hot Chili Peppers',\n", " 'type': 'artist',\n", " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", - " 'external_urls': {'spotify': 'https://open.spotify.com/album/30Perjew8HyGkdSmqguYyg'},\n", - " 'href': 'https://api.spotify.com/v1/albums/30Perjew8HyGkdSmqguYyg',\n", - " 'id': '30Perjew8HyGkdSmqguYyg',\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/album/43otFXrY0bgaq5fB3GrZj6'},\n", + " 'href': 'https://api.spotify.com/v1/albums/43otFXrY0bgaq5fB3GrZj6',\n", + " 'id': '43otFXrY0bgaq5fB3GrZj6',\n", " 'images': [{'height': 640,\n", - " 'url': 'https://i.scdn.co/image/ab67616d0000b273153d79816d853f2694b2cc70',\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000b27358406b3f1ac3ceaff7a64fef',\n", " 'width': 640},\n", " {'height': 300,\n", - " 'url': 'https://i.scdn.co/image/ab67616d00001e02153d79816d853f2694b2cc70',\n", + " 'url': 'https://i.scdn.co/image/ab67616d00001e0258406b3f1ac3ceaff7a64fef',\n", " 'width': 300},\n", " {'height': 64,\n", - " 'url': 'https://i.scdn.co/image/ab67616d00004851153d79816d853f2694b2cc70',\n", + " 'url': 'https://i.scdn.co/image/ab67616d0000485158406b3f1ac3ceaff7a64fef',\n", " 'width': 64}],\n", " 'is_playable': True,\n", - " 'name': 'Blood Sugar Sex Magik (Deluxe Edition)',\n", - " 'release_date': '1991-09-24',\n", + " 'name': 'The Getaway',\n", + " 'release_date': '2016-06-17',\n", " 'release_date_precision': 'day',\n", - " 'total_tracks': 19,\n", + " 'total_tracks': 13,\n", " 'type': 'album',\n", - " 'uri': 'spotify:album:30Perjew8HyGkdSmqguYyg'},\n", + " 'uri': 'spotify:album:43otFXrY0bgaq5fB3GrZj6'},\n", " 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n", " 'href': 'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5',\n", " 'id': '0L8ExT028jH3ddEcZwqJJ5',\n", @@ -919,69 +860,49 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:0L8ExT028jH3ddEcZwqJJ5'}],\n", " 'disc_number': 1,\n", - " 'duration_ms': 282906,\n", + " 'duration_ms': 302000,\n", " 'explicit': False,\n", - " 'external_ids': {'isrc': 'USWB19901574'},\n", - " 'external_urls': {'spotify': 'https://open.spotify.com/track/0uppYCG86ajpV2hSR3dJJ0'},\n", - " 'href': 'https://api.spotify.com/v1/tracks/0uppYCG86ajpV2hSR3dJJ0',\n", - " 'id': '0uppYCG86ajpV2hSR3dJJ0',\n", + " 'external_ids': {'isrc': 'USWB11600478'},\n", + " 'external_urls': {'spotify': 'https://open.spotify.com/track/2oaK4JLVnmRGIO9ytBE1bt'},\n", + " 'href': 'https://api.spotify.com/v1/tracks/2oaK4JLVnmRGIO9ytBE1bt',\n", + " 'id': '2oaK4JLVnmRGIO9ytBE1bt',\n", " 'is_local': False,\n", " 'is_playable': True,\n", - " 'name': 'Give It Away',\n", + " 'name': 'Dark Necessities',\n", " 'popularity': 76,\n", - " 'preview_url': 'https://p.scdn.co/mp3-preview/e0c62e6fb378167d40ab941124f9ed7b9911a35e?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", - " 'track_number': 9,\n", + " 'preview_url': 'https://p.scdn.co/mp3-preview/b2ed4a9710ca0512ce58df1702f375f4ad2e4c13?cid=bec9dd918ed04aca96b6eb3c699e443f',\n", + " 'track_number': 2,\n", " 'type': 'track',\n", - " 'uri': 'spotify:track:0uppYCG86ajpV2hSR3dJJ0'}]}" + " 'uri': 'spotify:track:2oaK4JLVnmRGIO9ytBE1bt'}]}" ] }, - "execution_count": 956, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "top_tracks_json = top_tracks_response.json()\n", - "top_tracks_json" + "parameter = '/top-tracks'\n", + "country_market = '?market=ES' \n", + "top_tracks_ep = artist_ep + parameter + country_market \n", + "top_tracks_ep_response = requests.get(top_tracks_ep, headers=header_info).json()\n", + "top_tracks_ep_response" ] }, { "cell_type": "code", - "execution_count": 957, - "id": "03760a1a", + "execution_count": 30, + "id": "e9cf4def", "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "['Under the Bridge',\n", - " 'Californication',\n", - " \"Can't Stop\",\n", - " 'Scar Tissue',\n", - " 'Otherside',\n", - " 'Snow (Hey Oh)',\n", - " 'Dani California',\n", - " 'By the Way',\n", - " 'Dark Necessities',\n", - " 'Give It Away']" - ] - }, - "execution_count": 957, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Top Tracks\n", - "[top_tracks_json['tracks'][i]['name'] for i in range(len(top_tracks_json['tracks']))]" - ] - }, - { - "cell_type": "code", - "execution_count": 958, - "id": "772e1d54", - "metadata": {}, - "outputs": [ + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Top Tracks DataFrame:\n" + ] + }, { "data": { "text/html": [ @@ -1005,9 +926,9 @@ " \n", " id\n", " href\n", - " name\n", + " song_name\n", " uri\n", - " tracks\n", + " artist_name\n", " \n", " \n", " \n", @@ -1017,7 +938,7 @@ " https://api.spotify.com/v1/tracks/3d9DChrdc6BO...\n", " Under the Bridge\n", " spotify:track:3d9DChrdc6BOeFsbrZ3Is0\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", + " Red Hot Chili Peppers\n", " \n", " \n", " 1\n", @@ -1025,7 +946,7 @@ " https://api.spotify.com/v1/tracks/48UPSzbZjgc4...\n", " Californication\n", " spotify:track:48UPSzbZjgc449aqz8bxox\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", + " Red Hot Chili Peppers\n", " \n", " \n", " 2\n", @@ -1033,7 +954,7 @@ " https://api.spotify.com/v1/tracks/3ZOEytgrvLwQ...\n", " Can't Stop\n", " spotify:track:3ZOEytgrvLwQaqXreDs2Jx\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", + " Red Hot Chili Peppers\n", " \n", " \n", " 3\n", @@ -1041,7 +962,7 @@ " https://api.spotify.com/v1/tracks/1G391cbiT3v3...\n", " Scar Tissue\n", " spotify:track:1G391cbiT3v3Cywg8T7DM1\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", + " Red Hot Chili Peppers\n", " \n", " \n", " 4\n", @@ -1049,7 +970,7 @@ " https://api.spotify.com/v1/tracks/64BbK9SFKH2j...\n", " Otherside\n", " spotify:track:64BbK9SFKH2jk86U3dGj2P\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", + " Red Hot Chili Peppers\n", " \n", " \n", " 5\n", @@ -1057,7 +978,7 @@ " https://api.spotify.com/v1/tracks/2aibwv5hGXSg...\n", " Snow (Hey Oh)\n", " spotify:track:2aibwv5hGXSgw7Yru8IYTO\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", + " Red Hot Chili Peppers\n", " \n", " \n", " 6\n", @@ -1065,7 +986,7 @@ " https://api.spotify.com/v1/tracks/10Nmj3JCNoMe...\n", " Dani California\n", " spotify:track:10Nmj3JCNoMeBQ87uw5j8k\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", + " Red Hot Chili Peppers\n", " \n", " \n", " 7\n", @@ -1073,23 +994,23 @@ " https://api.spotify.com/v1/tracks/1f2V8U1BiWaC...\n", " By the Way\n", " spotify:track:1f2V8U1BiWaC9aJWmpOARe\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", + " Red Hot Chili Peppers\n", " \n", " \n", " 8\n", - " 2oaK4JLVnmRGIO9ytBE1bt\n", - " https://api.spotify.com/v1/tracks/2oaK4JLVnmRG...\n", - " Dark Necessities\n", - " spotify:track:2oaK4JLVnmRGIO9ytBE1bt\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", - " \n", - " \n", - " 9\n", " 0uppYCG86ajpV2hSR3dJJ0\n", " https://api.spotify.com/v1/tracks/0uppYCG86ajp...\n", " Give It Away\n", " spotify:track:0uppYCG86ajpV2hSR3dJJ0\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", + " Red Hot Chili Peppers\n", + " \n", + " \n", + " 9\n", + " 2oaK4JLVnmRGIO9ytBE1bt\n", + " https://api.spotify.com/v1/tracks/2oaK4JLVnmRG...\n", + " Dark Necessities\n", + " spotify:track:2oaK4JLVnmRGIO9ytBE1bt\n", + " Red Hot Chili Peppers\n", " \n", " \n", "\n", @@ -1105,10 +1026,10 @@ "5 2aibwv5hGXSgw7Yru8IYTO https://api.spotify.com/v1/tracks/2aibwv5hGXSg... \n", "6 10Nmj3JCNoMeBQ87uw5j8k https://api.spotify.com/v1/tracks/10Nmj3JCNoMe... \n", "7 1f2V8U1BiWaC9aJWmpOARe https://api.spotify.com/v1/tracks/1f2V8U1BiWaC... \n", - "8 2oaK4JLVnmRGIO9ytBE1bt https://api.spotify.com/v1/tracks/2oaK4JLVnmRG... \n", - "9 0uppYCG86ajpV2hSR3dJJ0 https://api.spotify.com/v1/tracks/0uppYCG86ajp... \n", + "8 0uppYCG86ajpV2hSR3dJJ0 https://api.spotify.com/v1/tracks/0uppYCG86ajp... \n", + "9 2oaK4JLVnmRGIO9ytBE1bt https://api.spotify.com/v1/tracks/2oaK4JLVnmRG... \n", "\n", - " name uri \\\n", + " song_name uri \\\n", "0 Under the Bridge spotify:track:3d9DChrdc6BOeFsbrZ3Is0 \n", "1 Californication spotify:track:48UPSzbZjgc449aqz8bxox \n", "2 Can't Stop spotify:track:3ZOEytgrvLwQaqXreDs2Jx \n", @@ -1117,123 +1038,63 @@ "5 Snow (Hey Oh) spotify:track:2aibwv5hGXSgw7Yru8IYTO \n", "6 Dani California spotify:track:10Nmj3JCNoMeBQ87uw5j8k \n", "7 By the Way spotify:track:1f2V8U1BiWaC9aJWmpOARe \n", - "8 Dark Necessities spotify:track:2oaK4JLVnmRGIO9ytBE1bt \n", - "9 Give It Away spotify:track:0uppYCG86ajpV2hSR3dJJ0 \n", + "8 Give It Away spotify:track:0uppYCG86ajpV2hSR3dJJ0 \n", + "9 Dark Necessities spotify:track:2oaK4JLVnmRGIO9ytBE1bt \n", "\n", - " tracks \n", - "0 0L8ExT028jH3ddEcZwqJJ5 \n", - "1 0L8ExT028jH3ddEcZwqJJ5 \n", - "2 0L8ExT028jH3ddEcZwqJJ5 \n", - "3 0L8ExT028jH3ddEcZwqJJ5 \n", - "4 0L8ExT028jH3ddEcZwqJJ5 \n", - "5 0L8ExT028jH3ddEcZwqJJ5 \n", - "6 0L8ExT028jH3ddEcZwqJJ5 \n", - "7 0L8ExT028jH3ddEcZwqJJ5 \n", - "8 0L8ExT028jH3ddEcZwqJJ5 \n", - "9 0L8ExT028jH3ddEcZwqJJ5 " - ] - }, - "execution_count": 958, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Create DataFrames\n", - "top_tracks_df = pd.DataFrame(top_tracks_json['tracks'])[['id','href','name','uri']]\n", - "top_tracks_df['tracks'] = artist_id\n", - "top_tracks_df" - ] - }, - { - "cell_type": "code", - "execution_count": 959, - "id": "5910eed8", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Index(['external_urls', 'followers', 'genres', 'href', 'id', 'images', 'name',\n", - " 'popularity', 'type', 'uri', 'artist_id'],\n", - " dtype='object')\n", - "Index(['id', 'href', 'name', 'uri', 'tracks'], dtype='object')\n" - ] - } - ], - "source": [ - "print(artist_df.columns)\n", - "print(top_tracks_df.columns)" - ] - }, - { - "cell_type": "markdown", - "id": "b0de1f10", - "metadata": {}, - "source": [ - "### 3. Related artists" - ] - }, - { - "cell_type": "code", - "execution_count": 944, - "id": "6f29a8d9", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5/related-artists'" + " artist_name \n", + "0 Red Hot Chili Peppers \n", + "1 Red Hot Chili Peppers \n", + "2 Red Hot Chili Peppers \n", + "3 Red Hot Chili Peppers \n", + "4 Red Hot Chili Peppers \n", + "5 Red Hot Chili Peppers \n", + "6 Red Hot Chili Peppers \n", + "7 Red Hot Chili Peppers \n", + "8 Red Hot Chili Peppers \n", + "9 Red Hot Chili Peppers " ] }, - "execution_count": 944, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# Get Related artists\n", - "\n", - "method = '/related-artists'\n", + "def get_top_tracks(artist_id): \n", + " # Extracting relevant information for each track\n", + " tracks_data = []\n", + " for track in top_tracks_ep_response[\"tracks\"]:\n", + " track_data = {\n", + " \"id\": track[\"id\"],\n", + " \"href\": track[\"href\"],\n", + " \"song_name\": track[\"name\"],\n", + " \"uri\": track[\"uri\"],\n", + " \"artist_name\": artist_response[\"name\"]\n", + " }\n", + " tracks_data.append(track_data)\n", + " \n", + " # Creating the DataFrame\n", + " top_tracks_df = pd.DataFrame(tracks_data)\n", + " \n", + " return top_tracks_df\n", "\n", - "full_endpoint = base_url + resource + parameters + method\n", - "full_endpoint" - ] - }, - { - "cell_type": "code", - "execution_count": 945, - "id": "3c890e5e", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "200" - ] - }, - "execution_count": 945, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "related_artists_response = requests.get(full_endpoint, headers = header_info)\n", - "related_artists_response.status_code" + "# Get and display top tracks DataFrame\n", + "artist_top_tracks = get_top_tracks(artist_id)\n", + "print(\"\\nTop Tracks DataFrame:\")\n", + "artist_top_tracks" ] }, { "cell_type": "code", - "execution_count": 946, - "id": "516b044a", + "execution_count": 31, + "id": "148436e2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/7jy3rLJdDQY21OgRLCZ9sD'},\n", - " 'followers': {'href': None, 'total': 11362882},\n", + " 'followers': {'href': None, 'total': 11382646},\n", " 'genres': ['alternative metal',\n", " 'alternative rock',\n", " 'modern rock',\n", @@ -1256,7 +1117,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:7jy3rLJdDQY21OgRLCZ9sD'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2d0hyoQ5ynDBnkvAbJKORj'},\n", - " 'followers': {'href': None, 'total': 5667457},\n", + " 'followers': {'href': None, 'total': 5680557},\n", " 'genres': ['alternative metal',\n", " 'alternative rock',\n", " 'conscious hip hop',\n", @@ -1284,7 +1145,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:2d0hyoQ5ynDBnkvAbJKORj'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2ziB7fzrXBoh1HUPS6sVFn'},\n", - " 'followers': {'href': None, 'total': 4309698},\n", + " 'followers': {'href': None, 'total': 4317543},\n", " 'genres': ['alternative metal',\n", " 'alternative rock',\n", " 'grunge',\n", @@ -1310,7 +1171,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:2ziB7fzrXBoh1HUPS6sVFn'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/1w5Kfo2jwwIPruYS2UWh56'},\n", - " 'followers': {'href': None, 'total': 8454993},\n", + " 'followers': {'href': None, 'total': 8469091},\n", " 'genres': ['alternative metal',\n", " 'alternative rock',\n", " 'grunge',\n", @@ -1332,7 +1193,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:1w5Kfo2jwwIPruYS2UWh56'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/40Yq4vzPs9VNUrIBG5Jr2i'},\n", - " 'followers': {'href': None, 'total': 4760553},\n", + " 'followers': {'href': None, 'total': 4773525},\n", " 'genres': ['alternative metal',\n", " 'alternative rock',\n", " 'grunge',\n", @@ -1355,7 +1216,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:40Yq4vzPs9VNUrIBG5Jr2i'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6olE6TJLqED3rqDCT0FyPh'},\n", - " 'followers': {'href': None, 'total': 18411527},\n", + " 'followers': {'href': None, 'total': 18453988},\n", " 'genres': ['grunge', 'permanent wave', 'rock'],\n", " 'href': 'https://api.spotify.com/v1/artists/6olE6TJLqED3rqDCT0FyPh',\n", " 'id': '6olE6TJLqED3rqDCT0FyPh',\n", @@ -1376,7 +1237,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:6olE6TJLqED3rqDCT0FyPh'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5xUf6j4upBrXZPg6AI4MRK'},\n", - " 'followers': {'href': None, 'total': 4173767},\n", + " 'followers': {'href': None, 'total': 4182235},\n", " 'genres': ['alternative metal',\n", " 'alternative rock',\n", " 'classic rock',\n", @@ -1400,7 +1261,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:5xUf6j4upBrXZPg6AI4MRK'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3YcBF2ttyueytpXtEzn1Za'},\n", - " 'followers': {'href': None, 'total': 3135573},\n", + " 'followers': {'href': None, 'total': 3140865},\n", " 'genres': ['alternative metal',\n", " 'alternative rock',\n", " 'funk metal',\n", @@ -1424,7 +1285,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:3YcBF2ttyueytpXtEzn1Za'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5LfGQac0EIXyAN8aUwmNAQ'},\n", - " 'followers': {'href': None, 'total': 5233933},\n", + " 'followers': {'href': None, 'total': 5246913},\n", " 'genres': ['alternative metal',\n", " 'permanent wave',\n", " 'post-grunge',\n", @@ -1448,7 +1309,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:5LfGQac0EIXyAN8aUwmNAQ'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2UazAtjfzqBF0Nho2awK4z'},\n", - " 'followers': {'href': None, 'total': 3355895},\n", + " 'followers': {'href': None, 'total': 3362302},\n", " 'genres': ['alternative metal',\n", " 'alternative rock',\n", " 'classic rock',\n", @@ -1473,7 +1334,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:2UazAtjfzqBF0Nho2awK4z'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/64tNsm6TnZe2zpcMVMOoHL'},\n", - " 'followers': {'href': None, 'total': 4769618},\n", + " 'followers': {'href': None, 'total': 4781549},\n", " 'genres': ['alternative metal',\n", " 'alternative rock',\n", " 'grunge',\n", @@ -1496,7 +1357,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:64tNsm6TnZe2zpcMVMOoHL'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7oPftvlwr6VrsViSDV7fJY'},\n", - " 'followers': {'href': None, 'total': 14396087},\n", + " 'followers': {'href': None, 'total': 14430221},\n", " 'genres': ['modern rock', 'permanent wave', 'punk', 'rock'],\n", " 'href': 'https://api.spotify.com/v1/artists/7oPftvlwr6VrsViSDV7fJY',\n", " 'id': '7oPftvlwr6VrsViSDV7fJY',\n", @@ -1514,7 +1375,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:7oPftvlwr6VrsViSDV7fJY'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/36QJpDe2go2KgaRleHCDTp'},\n", - " 'followers': {'href': None, 'total': 13832236},\n", + " 'followers': {'href': None, 'total': 13858412},\n", " 'genres': ['album rock', 'classic rock', 'hard rock', 'rock'],\n", " 'href': 'https://api.spotify.com/v1/artists/36QJpDe2go2KgaRleHCDTp',\n", " 'id': '36QJpDe2go2KgaRleHCDTp',\n", @@ -1532,7 +1393,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:36QJpDe2go2KgaRleHCDTp'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5eAWCfyUhZtHHtBdNk56l1'},\n", - " 'followers': {'href': None, 'total': 9753467},\n", + " 'followers': {'href': None, 'total': 9787143},\n", " 'genres': ['alternative metal', 'nu metal', 'rap metal', 'rock'],\n", " 'href': 'https://api.spotify.com/v1/artists/5eAWCfyUhZtHHtBdNk56l1',\n", " 'id': '5eAWCfyUhZtHHtBdNk56l1',\n", @@ -1550,7 +1411,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:5eAWCfyUhZtHHtBdNk56l1'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/776Uo845nYHJpNaStv1Ds4'},\n", - " 'followers': {'href': None, 'total': 6413265},\n", + " 'followers': {'href': None, 'total': 6427068},\n", " 'genres': ['acid rock',\n", " 'album rock',\n", " 'alternative rock',\n", @@ -1575,7 +1436,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:776Uo845nYHJpNaStv1Ds4'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/4pejUc4iciQfgdX6OKulQn'},\n", - " 'followers': {'href': None, 'total': 3366471},\n", + " 'followers': {'href': None, 'total': 3373292},\n", " 'genres': ['alternative metal',\n", " 'alternative rock',\n", " 'grunge',\n", @@ -1601,7 +1462,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:4pejUc4iciQfgdX6OKulQn'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6FBDaR13swtiWwGhX1WQsP'},\n", - " 'followers': {'href': None, 'total': 7875556},\n", + " 'followers': {'href': None, 'total': 7894134},\n", " 'genres': ['alternative metal',\n", " 'modern rock',\n", " 'pop punk',\n", @@ -1624,7 +1485,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:6FBDaR13swtiWwGhX1WQsP'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/4F84IBURUo98rz4r61KF70'},\n", - " 'followers': {'href': None, 'total': 2934930},\n", + " 'followers': {'href': None, 'total': 2941525},\n", " 'genres': ['alternative rock',\n", " 'blues rock',\n", " 'detroit rock',\n", @@ -1649,7 +1510,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:4F84IBURUo98rz4r61KF70'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/165ZgPlLkK7bf5bDoFc6Sb'},\n", - " 'followers': {'href': None, 'total': 5422528},\n", + " 'followers': {'href': None, 'total': 5442508},\n", " 'genres': ['alternative metal',\n", " 'funk metal',\n", " 'nu metal',\n", @@ -1675,7 +1536,7 @@ " 'type': 'artist',\n", " 'uri': 'spotify:artist:165ZgPlLkK7bf5bDoFc6Sb'},\n", " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7Ey4PD4MYsKc5I2dolUwbH'},\n", - " 'followers': {'href': None, 'total': 13882544},\n", + " 'followers': {'href': None, 'total': 13908224},\n", " 'genres': ['album rock', 'classic rock', 'hard rock', 'rock'],\n", " 'href': 'https://api.spotify.com/v1/artists/7Ey4PD4MYsKc5I2dolUwbH',\n", " 'id': '7Ey4PD4MYsKc5I2dolUwbH',\n", @@ -1694,294 +1555,796 @@ " 'uri': 'spotify:artist:7Ey4PD4MYsKc5I2dolUwbH'}]}" ] }, - "execution_count": 946, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "related_artists_json = related_artists_response.json()\n", - "related_artists_json" + "method = '/related-artists'\n", + "rel_artists_ep = base_url + resource + artist_id + method\n", + "rel_artists_ep_response = requests.get(rel_artists_ep, headers=header_info).json()\n", + "rel_artists_ep_response" ] }, { "cell_type": "code", - "execution_count": 947, - "id": "fdcd1b96", - "metadata": { - "scrolled": true - }, + "execution_count": 14, + "id": "43aedba0", + "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "['Foo Fighters',\n", - " 'Rage Against The Machine',\n", - " 'Audioslave',\n", - " 'Pearl Jam',\n", - " 'The Smashing Pumpkins',\n", - " 'Nirvana',\n", - " 'Soundgarden',\n", - " 'Incubus',\n", - " 'The Offspring',\n", - " 'Stone Temple Pilots',\n", - " 'Alice In Chains',\n", - " 'Green Day',\n", - " 'Led Zeppelin',\n", - " 'System Of A Down',\n", - " 'Jimi Hendrix',\n", - " 'Queens of the Stone Age',\n", - " 'blink-182',\n", - " 'The White Stripes',\n", - " 'Limp Bizkit',\n", - " 'Aerosmith']" - ] - }, - "execution_count": 947, - "metadata": {}, - "output_type": "execute_result" + "ename": "NameError", + "evalue": "name 'rel_artists_ep_response' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[14], line 6\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m related_artists_df\n\u001b[0;32m 5\u001b[0m \u001b[38;5;66;03m# Get and display related artists DataFrame\u001b[39;00m\n\u001b[1;32m----> 6\u001b[0m related_artists_df \u001b[38;5;241m=\u001b[39m \u001b[43mget_related_artists\u001b[49m\u001b[43m(\u001b[49m\u001b[43martist_id\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mRelated Artists DataFrame:\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 8\u001b[0m related_artists_df\n", + "Cell \u001b[1;32mIn[14], line 2\u001b[0m, in \u001b[0;36mget_related_artists\u001b[1;34m(artist_id)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_related_artists\u001b[39m(artist_id): \n\u001b[1;32m----> 2\u001b[0m related_artists_df \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mDataFrame(\u001b[43mrel_artists_ep_response\u001b[49m[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124martists\u001b[39m\u001b[38;5;124m\"\u001b[39m])[[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mid\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m\"\u001b[39m]]\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m related_artists_df\n", + "\u001b[1;31mNameError\u001b[0m: name 'rel_artists_ep_response' is not defined" + ] } ], "source": [ - "# Related Artists\n", - "[related_artists_json['artists'][i]['name'] for i in range(len(related_artists_json['artists']))]" + "def get_related_artists(artist_id): \n", + " related_artists_df = pd.DataFrame(rel_artists_ep_response[\"artists\"])[[\"id\", \"name\"]]\n", + " return related_artists_df\n", + "\n", + "# Get and display related artists DataFrame\n", + "related_artists_df = get_related_artists(artist_id)\n", + "print(\"\\nRelated Artists DataFrame:\")\n", + "related_artists_df" ] }, { "cell_type": "code", - "execution_count": 960, - "id": "b6faa31a", + "execution_count": 33, + "id": "e2058344", "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", - "
idnamegenrespopularityfollowers
07jy3rLJdDQY21OgRLCZ9sDFoo Fighters[alternative metal, alternative rock, modern r...75{'href': None, 'total': 11362882}
12d0hyoQ5ynDBnkvAbJKORjRage Against The Machine[alternative metal, alternative rock, consciou...68{'href': None, 'total': 5667457}
22ziB7fzrXBoh1HUPS6sVFnAudioslave[alternative metal, alternative rock, grunge, ...65{'href': None, 'total': 4309698}
31w5Kfo2jwwIPruYS2UWh56Pearl Jam[alternative metal, alternative rock, grunge, ...71{'href': None, 'total': 8454993}
440Yq4vzPs9VNUrIBG5Jr2iThe Smashing Pumpkins[alternative metal, alternative rock, grunge, ...70{'href': None, 'total': 4760553}
\n", - "
" - ], - "text/plain": [ - " id name \\\n", - "0 7jy3rLJdDQY21OgRLCZ9sD Foo Fighters \n", - "1 2d0hyoQ5ynDBnkvAbJKORj Rage Against The Machine \n", - "2 2ziB7fzrXBoh1HUPS6sVFn Audioslave \n", - "3 1w5Kfo2jwwIPruYS2UWh56 Pearl Jam \n", - "4 40Yq4vzPs9VNUrIBG5Jr2i The Smashing Pumpkins \n", - "\n", - " genres popularity \\\n", - "0 [alternative metal, alternative rock, modern r... 75 \n", - "1 [alternative metal, alternative rock, consciou... 68 \n", - "2 [alternative metal, alternative rock, grunge, ... 65 \n", - "3 [alternative metal, alternative rock, grunge, ... 71 \n", - "4 [alternative metal, alternative rock, grunge, ... 70 \n", - "\n", - " followers \n", - "0 {'href': None, 'total': 11362882} \n", - "1 {'href': None, 'total': 5667457} \n", - "2 {'href': None, 'total': 4309698} \n", - "3 {'href': None, 'total': 8454993} \n", - "4 {'href': None, 'total': 4760553} " - ] - }, - "execution_count": 960, - "metadata": {}, - "output_type": "execute_result" + "ename": "JSONDecodeError", + "evalue": "Expecting value: line 1 column 1 (char 0)", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mJSONDecodeError\u001b[0m Traceback (most recent call last)", + "File \u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\site-packages\\requests\\models.py:971\u001b[0m, in \u001b[0;36mResponse.json\u001b[1;34m(self, **kwargs)\u001b[0m\n\u001b[0;32m 970\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 971\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m complexjson\u001b[38;5;241m.\u001b[39mloads(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtext, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 972\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m JSONDecodeError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 973\u001b[0m \u001b[38;5;66;03m# Catch JSON-related errors and raise as requests.JSONDecodeError\u001b[39;00m\n\u001b[0;32m 974\u001b[0m \u001b[38;5;66;03m# This aliases json.JSONDecodeError and simplejson.JSONDecodeError\u001b[39;00m\n", + "File \u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\json\\__init__.py:346\u001b[0m, in \u001b[0;36mloads\u001b[1;34m(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[0;32m 343\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;28mcls\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m object_hook \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[0;32m 344\u001b[0m parse_int \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m parse_float \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[0;32m 345\u001b[0m parse_constant \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m object_pairs_hook \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m kw):\n\u001b[1;32m--> 346\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_default_decoder\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdecode\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 347\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mcls\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", + "File \u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\json\\decoder.py:337\u001b[0m, in \u001b[0;36mJSONDecoder.decode\u001b[1;34m(self, s, _w)\u001b[0m\n\u001b[0;32m 333\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Return the Python representation of ``s`` (a ``str`` instance\u001b[39;00m\n\u001b[0;32m 334\u001b[0m \u001b[38;5;124;03mcontaining a JSON document).\u001b[39;00m\n\u001b[0;32m 335\u001b[0m \n\u001b[0;32m 336\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m--> 337\u001b[0m obj, end \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mraw_decode\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43midx\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_w\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mend\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 338\u001b[0m end \u001b[38;5;241m=\u001b[39m _w(s, end)\u001b[38;5;241m.\u001b[39mend()\n", + "File \u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\json\\decoder.py:355\u001b[0m, in \u001b[0;36mJSONDecoder.raw_decode\u001b[1;34m(self, s, idx)\u001b[0m\n\u001b[0;32m 354\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mStopIteration\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[1;32m--> 355\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m JSONDecodeError(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mExpecting value\u001b[39m\u001b[38;5;124m\"\u001b[39m, s, err\u001b[38;5;241m.\u001b[39mvalue) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 356\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m obj, end\n", + "\u001b[1;31mJSONDecodeError\u001b[0m: Expecting value: line 1 column 1 (char 0)", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mJSONDecodeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[33], line 4\u001b[0m\n\u001b[0;32m 2\u001b[0m country_market \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m?market=ES\u001b[39m\u001b[38;5;124m'\u001b[39m \n\u001b[0;32m 3\u001b[0m rel_top_tracks_ep \u001b[38;5;241m=\u001b[39m rel_artists_ep \u001b[38;5;241m+\u001b[39m parameter \u001b[38;5;241m+\u001b[39m country_market \n\u001b[1;32m----> 4\u001b[0m rel_top_tracks_ep_response \u001b[38;5;241m=\u001b[39m \u001b[43mrequests\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrel_top_tracks_ep\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mheader_info\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mjson\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\site-packages\\requests\\models.py:975\u001b[0m, in \u001b[0;36mResponse.json\u001b[1;34m(self, **kwargs)\u001b[0m\n\u001b[0;32m 971\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m complexjson\u001b[38;5;241m.\u001b[39mloads(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtext, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 972\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m JSONDecodeError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 973\u001b[0m \u001b[38;5;66;03m# Catch JSON-related errors and raise as requests.JSONDecodeError\u001b[39;00m\n\u001b[0;32m 974\u001b[0m \u001b[38;5;66;03m# This aliases json.JSONDecodeError and simplejson.JSONDecodeError\u001b[39;00m\n\u001b[1;32m--> 975\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m RequestsJSONDecodeError(e\u001b[38;5;241m.\u001b[39mmsg, e\u001b[38;5;241m.\u001b[39mdoc, e\u001b[38;5;241m.\u001b[39mpos)\n", + "\u001b[1;31mJSONDecodeError\u001b[0m: Expecting value: line 1 column 1 (char 0)" + ] } ], "source": [ - "# Create DataFrames\n", - "related_artists_df = pd.DataFrame(related_artists_json['artists'])[['id','name','genres','popularity','followers']]\n", - "related_artists_df.head()" + "parameter = '/top-tracks'\n", + "country_market = '?market=ES' \n", + "rel_top_tracks_ep = rel_artists_ep + parameter + country_market \n", + "rel_top_tracks_ep_response = requests.get(rel_top_tracks_ep, headers=header_info).json()" + ] + }, + { + "cell_type": "markdown", + "id": "178c8ecf", + "metadata": {}, + "source": [ + "### Aquí empieza a joderse todo" ] }, { "cell_type": "code", - "execution_count": 961, - "id": "76fd9618", + "execution_count": 16, + "id": "2c994d0b", "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", - "
related_idrelated_namerelated_genrespopularityrelated_followers
07jy3rLJdDQY21OgRLCZ9sDFoo Fighters[alternative metal, alternative rock, modern r...75{'href': None, 'total': 11362882}
12d0hyoQ5ynDBnkvAbJKORjRage Against The Machine[alternative metal, alternative rock, consciou...68{'href': None, 'total': 5667457}
22ziB7fzrXBoh1HUPS6sVFnAudioslave[alternative metal, alternative rock, grunge, ...65{'href': None, 'total': 4309698}
31w5Kfo2jwwIPruYS2UWh56Pearl Jam[alternative metal, alternative rock, grunge, ...71{'href': None, 'total': 8454993}
440Yq4vzPs9VNUrIBG5Jr2iThe Smashing Pumpkins[alternative metal, alternative rock, grunge, ...70{'href': None, 'total': 4760553}
\n", - "
" - ], - "text/plain": [ - " related_id related_name \\\n", - "0 7jy3rLJdDQY21OgRLCZ9sD Foo Fighters \n", - "1 2d0hyoQ5ynDBnkvAbJKORj Rage Against The Machine \n", - "2 2ziB7fzrXBoh1HUPS6sVFn Audioslave \n", - "3 1w5Kfo2jwwIPruYS2UWh56 Pearl Jam \n", - "4 40Yq4vzPs9VNUrIBG5Jr2i The Smashing Pumpkins \n", - "\n", - " related_genres popularity \\\n", - "0 [alternative metal, alternative rock, modern r... 75 \n", - "1 [alternative metal, alternative rock, consciou... 68 \n", - "2 [alternative metal, alternative rock, grunge, ... 65 \n", - "3 [alternative metal, alternative rock, grunge, ... 71 \n", - "4 [alternative metal, alternative rock, grunge, ... 70 \n", - "\n", - " related_followers \n", - "0 {'href': None, 'total': 11362882} \n", - "1 {'href': None, 'total': 5667457} \n", - "2 {'href': None, 'total': 4309698} \n", - "3 {'href': None, 'total': 8454993} \n", - "4 {'href': None, 'total': 4760553} " - ] - }, - "execution_count": 961, - "metadata": {}, - "output_type": "execute_result" + "ename": "NameError", + "evalue": "name 'related_artists_df' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[16], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# Crear una columna 'artist_name' en el DataFrame de artistas relacionados\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m related_artists_df[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124martist_name\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[43mrelated_artists_df\u001b[49m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m 4\u001b[0m \u001b[38;5;66;03m# Inicializar el DataFrame principal de top tracks\u001b[39;00m\n\u001b[0;32m 5\u001b[0m all_top_tracks_df \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mDataFrame(columns\u001b[38;5;241m=\u001b[39m[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mid\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhref\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msong_name\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muri\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124martist_name\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n", + "\u001b[1;31mNameError\u001b[0m: name 'related_artists_df' is not defined" + ] } ], "source": [ - "# Rename columns\n", - "related_artists_df = related_artists_df.rename(columns={'id':'related_id',\n", - " 'name':'related_name',\n", - " 'genres':'related_genres',\n", - " 'popularity': 'popularity',\n", - " 'followers':'related_followers'\n", - " })\n", - "related_artists_df.head()" + "# Crear una columna 'artist_name' en el DataFrame de artistas relacionados\n", + "related_artists_df['artist_name'] = related_artists_df['name']\n", + "\n", + "# Inicializar el DataFrame principal de top tracks\n", + "all_top_tracks_df = pd.DataFrame(columns=[\"id\", \"href\", \"song_name\", \"uri\", \"artist_name\"])\n", + "\n", + "# Iterar sobre los artistas relacionados y agregar sus top tracks al DataFrame principal\n", + "for index, row in related_artists_df.iterrows():\n", + " related_artist_id = row['id']\n", + " related_artist_name = row['artist_name']\n", + " \n", + " # Obtener los top tracks del artista relacionado y agregarlos al DataFrame principal\n", + " related_artist_top_tracks = get_top_tracks_for_related_artist(related_artist_id, related_artist_name)\n", + " \n", + " # Concatenar el DataFrame del artista relacionado al DataFrame principal\n", + " all_top_tracks_df = pd.concat([all_top_tracks_df, related_artist_top_tracks], ignore_index=True)\n", + "\n", + "# Mostrar el DataFrame de top tracks para todos los artistas relacionados\n", + "print(\"\\nTop Tracks for All Related Artists:\")\n", + "\n", + "all_top_tracks_df = all_top_tracks_df + artist_top_tracks\n", + "all_top_tracks_df\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "200eeefe", + "metadata": {}, + "source": [ + "### 3. Related artists" ] }, { "cell_type": "code", - "execution_count": 962, - "id": "8d1f3639", + "execution_count": 252, + "id": "e800124f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5/related-artists\n" + ] + } + ], + "source": [ + "method = '/related-artists'\n", + "# argument = \"market = ES\"\n", + "rel_artists_ep = base_url + resource + artist_id + method \n", + "print(rel_artists_ep)" + ] + }, + { + "cell_type": "code", + "execution_count": 253, + "id": "234592f2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 253, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rel_artists_ep_response = requests.get(rel_artists_ep, headers=header_info)\n", + "rel_artists_ep_response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": 254, + "id": "8d16f809", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/7jy3rLJdDQY21OgRLCZ9sD'},\n", + " 'followers': {'href': None, 'total': 11379717},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'modern rock',\n", + " 'permanent wave',\n", + " 'post-grunge',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/7jy3rLJdDQY21OgRLCZ9sD',\n", + " 'id': '7jy3rLJdDQY21OgRLCZ9sD',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebc884df599abc793c116cdf15',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174c884df599abc793c116cdf15',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178c884df599abc793c116cdf15',\n", + " 'width': 160}],\n", + " 'name': 'Foo Fighters',\n", + " 'popularity': 75,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7jy3rLJdDQY21OgRLCZ9sD'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2d0hyoQ5ynDBnkvAbJKORj'},\n", + " 'followers': {'href': None, 'total': 5678642},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'conscious hip hop',\n", + " 'funk metal',\n", + " 'hard rock',\n", + " 'nu metal',\n", + " 'political hip hop',\n", + " 'post-grunge',\n", + " 'rap metal',\n", + " 'rap rock',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2d0hyoQ5ynDBnkvAbJKORj',\n", + " 'id': '2d0hyoQ5ynDBnkvAbJKORj',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebda4bd2b213cae330e2a4a901',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174da4bd2b213cae330e2a4a901',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178da4bd2b213cae330e2a4a901',\n", + " 'width': 160}],\n", + " 'name': 'Rage Against The Machine',\n", + " 'popularity': 68,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2d0hyoQ5ynDBnkvAbJKORj'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2ziB7fzrXBoh1HUPS6sVFn'},\n", + " 'followers': {'href': None, 'total': 4316350},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'grunge',\n", + " 'hard rock',\n", + " 'nu metal',\n", + " 'permanent wave',\n", + " 'post-grunge',\n", + " 'rock',\n", + " 'supergroup'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2ziB7fzrXBoh1HUPS6sVFn',\n", + " 'id': '2ziB7fzrXBoh1HUPS6sVFn',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb5a865295befda9e060a72cb0',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051745a865295befda9e060a72cb0',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1785a865295befda9e060a72cb0',\n", + " 'width': 160}],\n", + " 'name': 'Audioslave',\n", + " 'popularity': 65,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2ziB7fzrXBoh1HUPS6sVFn'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/1w5Kfo2jwwIPruYS2UWh56'},\n", + " 'followers': {'href': None, 'total': 8467054},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'grunge',\n", + " 'permanent wave',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/1w5Kfo2jwwIPruYS2UWh56',\n", + " 'id': '1w5Kfo2jwwIPruYS2UWh56',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb122d1145d880736383742ebc',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174122d1145d880736383742ebc',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178122d1145d880736383742ebc',\n", + " 'width': 160}],\n", + " 'name': 'Pearl Jam',\n", + " 'popularity': 71,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:1w5Kfo2jwwIPruYS2UWh56'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/40Yq4vzPs9VNUrIBG5Jr2i'},\n", + " 'followers': {'href': None, 'total': 4771614},\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/6olE6TJLqED3rqDCT0FyPh'},\n", + " 'followers': {'href': None, 'total': 18447864},\n", + " 'genres': ['grunge', 'permanent wave', 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6olE6TJLqED3rqDCT0FyPh',\n", + " 'id': '6olE6TJLqED3rqDCT0FyPh',\n", + " 'images': [{'height': 1057,\n", + " 'url': 'https://i.scdn.co/image/84282c28d851a700132356381fcfbadc67ff498b',\n", + " 'width': 1000},\n", + " {'height': 677,\n", + " 'url': 'https://i.scdn.co/image/a4e10b79a642e9891383448cbf37d7266a6883d6',\n", + " 'width': 640},\n", + " {'height': 211,\n", + " 'url': 'https://i.scdn.co/image/42ae0f180f16e2f21c1f2212717fc436f5b95451',\n", + " 'width': 200},\n", + " {'height': 68,\n", + " 'url': 'https://i.scdn.co/image/e797ad36d56c3fc8fa06c6fe91263a15bf8391b8',\n", + " 'width': 64}],\n", + " 'name': 'Nirvana',\n", + " 'popularity': 78,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6olE6TJLqED3rqDCT0FyPh'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5xUf6j4upBrXZPg6AI4MRK'},\n", + " 'followers': {'href': None, 'total': 4180962},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'classic rock',\n", + " 'grunge',\n", + " 'hard rock',\n", + " 'nu metal',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/5xUf6j4upBrXZPg6AI4MRK',\n", + " 'id': '5xUf6j4upBrXZPg6AI4MRK',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebafa254b2a224584485286526',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174afa254b2a224584485286526',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178afa254b2a224584485286526',\n", + " 'width': 160}],\n", + " 'name': 'Soundgarden',\n", + " 'popularity': 64,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:5xUf6j4upBrXZPg6AI4MRK'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/3YcBF2ttyueytpXtEzn1Za'},\n", + " 'followers': {'href': None, 'total': 3139966},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'funk metal',\n", + " 'funk rock',\n", + " 'nu metal',\n", + " 'post-grunge',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/3YcBF2ttyueytpXtEzn1Za',\n", + " 'id': '3YcBF2ttyueytpXtEzn1Za',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebbaebf3a81961bdf7173ab959',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174baebf3a81961bdf7173ab959',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178baebf3a81961bdf7173ab959',\n", + " 'width': 160}],\n", + " 'name': 'Incubus',\n", + " 'popularity': 66,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:3YcBF2ttyueytpXtEzn1Za'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5LfGQac0EIXyAN8aUwmNAQ'},\n", + " 'followers': {'href': None, 'total': 5244959},\n", + " 'genres': ['alternative metal',\n", + " 'permanent wave',\n", + " 'post-grunge',\n", + " 'punk',\n", + " 'rock',\n", + " 'skate punk',\n", + " 'socal pop punk'],\n", + " 'href': 'https://api.spotify.com/v1/artists/5LfGQac0EIXyAN8aUwmNAQ',\n", + " 'id': '5LfGQac0EIXyAN8aUwmNAQ',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebd7c5bbf32459922a72ec0d31',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174d7c5bbf32459922a72ec0d31',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178d7c5bbf32459922a72ec0d31',\n", + " 'width': 160}],\n", + " 'name': 'The Offspring',\n", + " 'popularity': 74,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:5LfGQac0EIXyAN8aUwmNAQ'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/2UazAtjfzqBF0Nho2awK4z'},\n", + " 'followers': {'href': None, 'total': 3361298},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'classic rock',\n", + " 'grunge',\n", + " 'hard rock',\n", + " 'nu metal',\n", + " 'post-grunge',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/2UazAtjfzqBF0Nho2awK4z',\n", + " 'id': '2UazAtjfzqBF0Nho2awK4z',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb4bb64f87db255d76538b905f',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051744bb64f87db255d76538b905f',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1784bb64f87db255d76538b905f',\n", + " 'width': 160}],\n", + " 'name': 'Stone Temple Pilots',\n", + " 'popularity': 64,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:2UazAtjfzqBF0Nho2awK4z'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/64tNsm6TnZe2zpcMVMOoHL'},\n", + " 'followers': {'href': None, 'total': 4779812},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'grunge',\n", + " 'hard rock',\n", + " 'nu metal',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/64tNsm6TnZe2zpcMVMOoHL',\n", + " 'id': '64tNsm6TnZe2zpcMVMOoHL',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb6114a63659d0d5c0a801f733',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051746114a63659d0d5c0a801f733',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1786114a63659d0d5c0a801f733',\n", + " 'width': 160}],\n", + " 'name': 'Alice In Chains',\n", + " 'popularity': 69,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:64tNsm6TnZe2zpcMVMOoHL'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7oPftvlwr6VrsViSDV7fJY'},\n", + " 'followers': {'href': None, 'total': 14424628},\n", + " 'genres': ['modern rock', 'permanent wave', 'punk', 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/7oPftvlwr6VrsViSDV7fJY',\n", + " 'id': '7oPftvlwr6VrsViSDV7fJY',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb6ff0cd5ef2ecf733804984bb',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051746ff0cd5ef2ecf733804984bb',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1786ff0cd5ef2ecf733804984bb',\n", + " 'width': 160}],\n", + " 'name': 'Green Day',\n", + " 'popularity': 78,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7oPftvlwr6VrsViSDV7fJY'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/36QJpDe2go2KgaRleHCDTp'},\n", + " 'followers': {'href': None, 'total': 13854731},\n", + " 'genres': ['album rock', 'classic rock', 'hard rock', 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/36QJpDe2go2KgaRleHCDTp',\n", + " 'id': '36QJpDe2go2KgaRleHCDTp',\n", + " 'images': [{'height': 600,\n", + " 'url': 'https://i.scdn.co/image/207803ce008388d3427a685254f9de6a8f61dc2e',\n", + " 'width': 600},\n", + " {'height': 200,\n", + " 'url': 'https://i.scdn.co/image/b0248a44865493e6a03832aa89854ada16ff07a8',\n", + " 'width': 200},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/16eb3cdae0d824b520ac17710e943a99d3ef6602',\n", + " 'width': 64}],\n", + " 'name': 'Led Zeppelin',\n", + " 'popularity': 73,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:36QJpDe2go2KgaRleHCDTp'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/5eAWCfyUhZtHHtBdNk56l1'},\n", + " 'followers': {'href': None, 'total': 9782236},\n", + " 'genres': ['alternative metal', 'nu metal', 'rap metal', 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/5eAWCfyUhZtHHtBdNk56l1',\n", + " 'id': '5eAWCfyUhZtHHtBdNk56l1',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb60063d3451ade8f9fab397c2',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000517460063d3451ade8f9fab397c2',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f17860063d3451ade8f9fab397c2',\n", + " 'width': 160}],\n", + " 'name': 'System Of A Down',\n", + " 'popularity': 76,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:5eAWCfyUhZtHHtBdNk56l1'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/776Uo845nYHJpNaStv1Ds4'},\n", + " 'followers': {'href': None, 'total': 6425131},\n", + " 'genres': ['acid rock',\n", + " 'album rock',\n", + " 'alternative rock',\n", + " 'classic rock',\n", + " 'hard rock',\n", + " 'proto-metal',\n", + " 'psychedelic rock',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/776Uo845nYHJpNaStv1Ds4',\n", + " 'id': '776Uo845nYHJpNaStv1Ds4',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb31f6ab67e6025de876475814',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000517431f6ab67e6025de876475814',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f17831f6ab67e6025de876475814',\n", + " 'width': 160}],\n", + " 'name': 'Jimi Hendrix',\n", + " 'popularity': 67,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:776Uo845nYHJpNaStv1Ds4'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/4pejUc4iciQfgdX6OKulQn'},\n", + " 'followers': {'href': None, 'total': 3372276},\n", + " 'genres': ['alternative metal',\n", + " 'alternative rock',\n", + " 'grunge',\n", + " 'modern rock',\n", + " 'nu metal',\n", + " 'palm desert scene',\n", + " 'rock',\n", + " 'stoner metal',\n", + " 'stoner rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/4pejUc4iciQfgdX6OKulQn',\n", + " 'id': '4pejUc4iciQfgdX6OKulQn',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb909b2c4b7c768ee03445cd10',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174909b2c4b7c768ee03445cd10',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178909b2c4b7c768ee03445cd10',\n", + " 'width': 160}],\n", + " 'name': 'Queens of the Stone Age',\n", + " 'popularity': 68,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:4pejUc4iciQfgdX6OKulQn'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/6FBDaR13swtiWwGhX1WQsP'},\n", + " 'followers': {'href': None, 'total': 7891472},\n", + " 'genres': ['alternative metal',\n", + " 'modern rock',\n", + " 'pop punk',\n", + " 'punk',\n", + " 'rock',\n", + " 'socal pop punk'],\n", + " 'href': 'https://api.spotify.com/v1/artists/6FBDaR13swtiWwGhX1WQsP',\n", + " 'id': '6FBDaR13swtiWwGhX1WQsP',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb5da36f8b98dd965336a1507a',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab676161000051745da36f8b98dd965336a1507a',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f1785da36f8b98dd965336a1507a',\n", + " 'width': 160}],\n", + " 'name': 'blink-182',\n", + " 'popularity': 79,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:6FBDaR13swtiWwGhX1WQsP'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/4F84IBURUo98rz4r61KF70'},\n", + " 'followers': {'href': None, 'total': 2940595},\n", + " 'genres': ['alternative rock',\n", + " 'blues rock',\n", + " 'detroit rock',\n", + " 'garage rock',\n", + " 'modern blues rock',\n", + " 'permanent wave',\n", + " 'punk blues',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/4F84IBURUo98rz4r61KF70',\n", + " 'id': '4F84IBURUo98rz4r61KF70',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5eb70cc06de8fc28226d4743cd9',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000517470cc06de8fc28226d4743cd9',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f17870cc06de8fc28226d4743cd9',\n", + " 'width': 160}],\n", + " 'name': 'The White Stripes',\n", + " 'popularity': 68,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:4F84IBURUo98rz4r61KF70'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/165ZgPlLkK7bf5bDoFc6Sb'},\n", + " 'followers': {'href': None, 'total': 5439630},\n", + " 'genres': ['alternative metal',\n", + " 'funk metal',\n", + " 'nu metal',\n", + " 'post-grunge',\n", + " 'rap metal',\n", + " 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/165ZgPlLkK7bf5bDoFc6Sb',\n", + " 'id': '165ZgPlLkK7bf5bDoFc6Sb',\n", + " 'images': [{'height': 1006,\n", + " 'url': 'https://i.scdn.co/image/4654955890cb62a6abe9daadfd2b3ecdee8036e4',\n", + " 'width': 1000},\n", + " {'height': 644,\n", + " 'url': 'https://i.scdn.co/image/c8e241c3b7ddb2839be99acf9a1ad2d73f04b936',\n", + " 'width': 640},\n", + " {'height': 201,\n", + " 'url': 'https://i.scdn.co/image/38532b2db9bc627567271da917855a59be788860',\n", + " 'width': 200},\n", + " {'height': 64,\n", + " 'url': 'https://i.scdn.co/image/67ab66b1154c3115005086d60853fc954717a2ea',\n", + " 'width': 64}],\n", + " 'name': 'Limp Bizkit',\n", + " 'popularity': 72,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:165ZgPlLkK7bf5bDoFc6Sb'},\n", + " {'external_urls': {'spotify': 'https://open.spotify.com/artist/7Ey4PD4MYsKc5I2dolUwbH'},\n", + " 'followers': {'href': None, 'total': 13904602},\n", + " 'genres': ['album rock', 'classic rock', 'hard rock', 'rock'],\n", + " 'href': 'https://api.spotify.com/v1/artists/7Ey4PD4MYsKc5I2dolUwbH',\n", + " 'id': '7Ey4PD4MYsKc5I2dolUwbH',\n", + " 'images': [{'height': 640,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000e5ebc5733401b4689b2064458e7d',\n", + " 'width': 640},\n", + " {'height': 320,\n", + " 'url': 'https://i.scdn.co/image/ab67616100005174c5733401b4689b2064458e7d',\n", + " 'width': 320},\n", + " {'height': 160,\n", + " 'url': 'https://i.scdn.co/image/ab6761610000f178c5733401b4689b2064458e7d',\n", + " 'width': 160}],\n", + " 'name': 'Aerosmith',\n", + " 'popularity': 73,\n", + " 'type': 'artist',\n", + " 'uri': 'spotify:artist:7Ey4PD4MYsKc5I2dolUwbH'}]}" + ] + }, + "execution_count": 254, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rel_artists_ep_response.json()" + ] + }, + { + "cell_type": "markdown", + "id": "b80c877b", + "metadata": {}, + "source": [ + "### 4. Related artist top tracks" + ] + }, + { + "cell_type": "code", + "execution_count": 264, + "id": "636b4e31", + "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", + "
idhrefnameuri
03d9DChrdc6BOeFsbrZ3Is0https://api.spotify.com/v1/tracks/3d9DChrdc6BO...Under the Bridgespotify:track:3d9DChrdc6BOeFsbrZ3Is0
148UPSzbZjgc449aqz8bxoxhttps://api.spotify.com/v1/tracks/48UPSzbZjgc4...Californicationspotify:track:48UPSzbZjgc449aqz8bxox
23ZOEytgrvLwQaqXreDs2Jxhttps://api.spotify.com/v1/tracks/3ZOEytgrvLwQ...Can't Stopspotify:track:3ZOEytgrvLwQaqXreDs2Jx
31G391cbiT3v3Cywg8T7DM1https://api.spotify.com/v1/tracks/1G391cbiT3v3...Scar Tissuespotify:track:1G391cbiT3v3Cywg8T7DM1
464BbK9SFKH2jk86U3dGj2Phttps://api.spotify.com/v1/tracks/64BbK9SFKH2j...Othersidespotify:track:64BbK9SFKH2jk86U3dGj2P
\n", + "
" + ], + "text/plain": [ + " id href \\\n", + "0 3d9DChrdc6BOeFsbrZ3Is0 https://api.spotify.com/v1/tracks/3d9DChrdc6BO... \n", + "1 48UPSzbZjgc449aqz8bxox https://api.spotify.com/v1/tracks/48UPSzbZjgc4... \n", + "2 3ZOEytgrvLwQaqXreDs2Jx https://api.spotify.com/v1/tracks/3ZOEytgrvLwQ... \n", + "3 1G391cbiT3v3Cywg8T7DM1 https://api.spotify.com/v1/tracks/1G391cbiT3v3... \n", + "4 64BbK9SFKH2jk86U3dGj2P https://api.spotify.com/v1/tracks/64BbK9SFKH2j... \n", + "\n", + " name uri \n", + "0 Under the Bridge spotify:track:3d9DChrdc6BOeFsbrZ3Is0 \n", + "1 Californication spotify:track:48UPSzbZjgc449aqz8bxox \n", + "2 Can't Stop spotify:track:3ZOEytgrvLwQaqXreDs2Jx \n", + "3 Scar Tissue spotify:track:1G391cbiT3v3Cywg8T7DM1 \n", + "4 Otherside spotify:track:64BbK9SFKH2jk86U3dGj2P " + ] + }, + "execution_count": 264, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Getting the chosen artist top tracks\n", + "def get_top_tracks(artist_id): \n", + " parameter = '/top-tracks'\n", + " country_market = '?market=ES' \n", + " top_tracks_ep = artist_ep + parameter + country_market \n", + " top_tracks_ep_response = requests.get(top_tracks_ep, headers=header_info).json()\n", + " top_tracks_df = pd.DataFrame(top_tracks_ep_response[\"tracks\"])[[\"id\", \"href\", \"name\", \"uri\"]]\n", + " \n", + " return top_tracks_df\n", + "\n", + "artist_top_tracks = get_top_tracks(artist_id)\n", + "artist_top_tracks.head()" + ] + }, + { + "cell_type": "markdown", + "id": "02404c2d", + "metadata": {}, + "source": [ + "### 4. Release playlist" + ] + }, + { + "cell_type": "code", + "execution_count": 307, + "id": "6769a790", "metadata": {}, "outputs": [ { @@ -2005,12 +2368,8 @@ " \n", " \n", " \n", - " related_id\n", - " related_name\n", - " related_genres\n", - " popularity\n", - " related_followers\n", - " artist_id\n", + " id\n", + " name\n", " \n", " \n", " \n", @@ -2018,79 +2377,650 @@ " 0\n", " 7jy3rLJdDQY21OgRLCZ9sD\n", " Foo Fighters\n", - " [alternative metal, alternative rock, modern r...\n", - " 75\n", - " {'href': None, 'total': 11362882}\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", " \n", " \n", " 1\n", " 2d0hyoQ5ynDBnkvAbJKORj\n", " Rage Against The Machine\n", - " [alternative metal, alternative rock, consciou...\n", - " 68\n", - " {'href': None, 'total': 5667457}\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", " \n", " \n", " 2\n", " 2ziB7fzrXBoh1HUPS6sVFn\n", " Audioslave\n", - " [alternative metal, alternative rock, grunge, ...\n", - " 65\n", - " {'href': None, 'total': 4309698}\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", " \n", " \n", " 3\n", " 1w5Kfo2jwwIPruYS2UWh56\n", " Pearl Jam\n", - " [alternative metal, alternative rock, grunge, ...\n", - " 71\n", - " {'href': None, 'total': 8454993}\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", " \n", " \n", " 4\n", " 40Yq4vzPs9VNUrIBG5Jr2i\n", " The Smashing Pumpkins\n", - " [alternative metal, alternative rock, grunge, ...\n", - " 70\n", - " {'href': None, 'total': 4760553}\n", - " 0L8ExT028jH3ddEcZwqJJ5\n", + " \n", + " \n", + " 5\n", + " 6olE6TJLqED3rqDCT0FyPh\n", + " Nirvana\n", + " \n", + " \n", + " 6\n", + " 5xUf6j4upBrXZPg6AI4MRK\n", + " Soundgarden\n", + " \n", + " \n", + " 7\n", + " 3YcBF2ttyueytpXtEzn1Za\n", + " Incubus\n", + " \n", + " \n", + " 8\n", + " 5LfGQac0EIXyAN8aUwmNAQ\n", + " The Offspring\n", + " \n", + " \n", + " 9\n", + " 2UazAtjfzqBF0Nho2awK4z\n", + " Stone Temple Pilots\n", + " \n", + " \n", + " 10\n", + " 64tNsm6TnZe2zpcMVMOoHL\n", + " Alice In Chains\n", + " \n", + " \n", + " 11\n", + " 7oPftvlwr6VrsViSDV7fJY\n", + " Green Day\n", + " \n", + " \n", + " 12\n", + " 36QJpDe2go2KgaRleHCDTp\n", + " Led Zeppelin\n", + " \n", + " \n", + " 13\n", + " 5eAWCfyUhZtHHtBdNk56l1\n", + " System Of A Down\n", + " \n", + " \n", + " 14\n", + " 776Uo845nYHJpNaStv1Ds4\n", + " Jimi Hendrix\n", + " \n", + " \n", + " 15\n", + " 4pejUc4iciQfgdX6OKulQn\n", + " Queens of the Stone Age\n", + " \n", + " \n", + " 16\n", + " 6FBDaR13swtiWwGhX1WQsP\n", + " blink-182\n", + " \n", + " \n", + " 17\n", + " 4F84IBURUo98rz4r61KF70\n", + " The White Stripes\n", + " \n", + " \n", + " 18\n", + " 165ZgPlLkK7bf5bDoFc6Sb\n", + " Limp Bizkit\n", + " \n", + " \n", + " 19\n", + " 7Ey4PD4MYsKc5I2dolUwbH\n", + " Aerosmith\n", " \n", " \n", "\n", "" ], "text/plain": [ - " related_id related_name \\\n", - "0 7jy3rLJdDQY21OgRLCZ9sD Foo Fighters \n", - "1 2d0hyoQ5ynDBnkvAbJKORj Rage Against The Machine \n", - "2 2ziB7fzrXBoh1HUPS6sVFn Audioslave \n", - "3 1w5Kfo2jwwIPruYS2UWh56 Pearl Jam \n", - "4 40Yq4vzPs9VNUrIBG5Jr2i The Smashing Pumpkins \n", - "\n", - " related_genres popularity \\\n", - "0 [alternative metal, alternative rock, modern r... 75 \n", - "1 [alternative metal, alternative rock, consciou... 68 \n", - "2 [alternative metal, alternative rock, grunge, ... 65 \n", - "3 [alternative metal, alternative rock, grunge, ... 71 \n", - "4 [alternative metal, alternative rock, grunge, ... 70 \n", - "\n", - " related_followers artist_id \n", - "0 {'href': None, 'total': 11362882} 0L8ExT028jH3ddEcZwqJJ5 \n", - "1 {'href': None, 'total': 5667457} 0L8ExT028jH3ddEcZwqJJ5 \n", - "2 {'href': None, 'total': 4309698} 0L8ExT028jH3ddEcZwqJJ5 \n", - "3 {'href': None, 'total': 8454993} 0L8ExT028jH3ddEcZwqJJ5 \n", - "4 {'href': None, 'total': 4760553} 0L8ExT028jH3ddEcZwqJJ5 " + " id name\n", + "0 7jy3rLJdDQY21OgRLCZ9sD Foo Fighters\n", + "1 2d0hyoQ5ynDBnkvAbJKORj Rage Against The Machine\n", + "2 2ziB7fzrXBoh1HUPS6sVFn Audioslave\n", + "3 1w5Kfo2jwwIPruYS2UWh56 Pearl Jam\n", + "4 40Yq4vzPs9VNUrIBG5Jr2i The Smashing Pumpkins\n", + "5 6olE6TJLqED3rqDCT0FyPh Nirvana\n", + "6 5xUf6j4upBrXZPg6AI4MRK Soundgarden\n", + "7 3YcBF2ttyueytpXtEzn1Za Incubus\n", + "8 5LfGQac0EIXyAN8aUwmNAQ The Offspring\n", + "9 2UazAtjfzqBF0Nho2awK4z Stone Temple Pilots\n", + "10 64tNsm6TnZe2zpcMVMOoHL Alice In Chains\n", + "11 7oPftvlwr6VrsViSDV7fJY Green Day\n", + "12 36QJpDe2go2KgaRleHCDTp Led Zeppelin\n", + "13 5eAWCfyUhZtHHtBdNk56l1 System Of A Down\n", + "14 776Uo845nYHJpNaStv1Ds4 Jimi Hendrix\n", + "15 4pejUc4iciQfgdX6OKulQn Queens of the Stone Age\n", + "16 6FBDaR13swtiWwGhX1WQsP blink-182\n", + "17 4F84IBURUo98rz4r61KF70 The White Stripes\n", + "18 165ZgPlLkK7bf5bDoFc6Sb Limp Bizkit\n", + "19 7Ey4PD4MYsKc5I2dolUwbH Aerosmith" ] }, - "execution_count": 962, + "execution_count": 307, "metadata": {}, "output_type": "execute_result" } ], + "source": [ + "# Getting the related-artists\n", + "def get_related_artists(artist_id):\n", + " rel_artists_ep = base_url + resource + artist_id + method\n", + " rel_artists_ep_response = requests.get(rel_artists_ep, headers=header_info).json() \n", + " related_artists_df = pd.DataFrame(rel_artists_ep_response[\"artists\"])[[\"id\", \"name\"]]\n", + " related_artists_df\n", + " return related_artists_df\n", + "\n", + "related_artists_df = get_related_artists(artist_id)\n", + "related_artists_df" + ] + }, + { + "cell_type": "code", + "execution_count": 284, + "id": "59bd36bc", + "metadata": {}, + "outputs": [], + "source": [ + "def make_playlist(dataframe):\n", + " playlist = pd.DataFrame() \n", + " for artist_id in dataframe:\n", + " artist_name = related_artists_df[related_artists_df[\"name\"] == artist_id][\"id\"].values[0]\n", + " artist_top_tracks = get_top_tracks(artist_id)\n", + " artist_top_tracks[\"artist_name\"] = artist_name\n", + " playlist = pd.concat([playlist, artist_top_tracks])\n", + " playlist = playlist.reset_index(drop=True)\n", + " return playlist" + ] + }, + { + "cell_type": "code", + "execution_count": 285, + "id": "9a29fd18", + "metadata": {}, + "outputs": [ + { + "ename": "IndexError", + "evalue": "index 0 is out of bounds for axis 0 with size 0", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[285], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m playlist \u001b[38;5;241m=\u001b[39m \u001b[43mmake_playlist\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrelated_artists_df\u001b[49m\u001b[43m[\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mid\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# Asegúrate de seleccionar solo la columna 'id'\u001b[39;00m\n\u001b[0;32m 2\u001b[0m playlist\u001b[38;5;241m.\u001b[39mhead(\u001b[38;5;241m30\u001b[39m)\n", + "Cell \u001b[1;32mIn[284], line 4\u001b[0m, in \u001b[0;36mmake_playlist\u001b[1;34m(dataframe)\u001b[0m\n\u001b[0;32m 2\u001b[0m playlist \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mDataFrame() \n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m artist_id \u001b[38;5;129;01min\u001b[39;00m dataframe:\n\u001b[1;32m----> 4\u001b[0m artist_name \u001b[38;5;241m=\u001b[39m \u001b[43mrelated_artists_df\u001b[49m\u001b[43m[\u001b[49m\u001b[43mrelated_artists_df\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mname\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m==\u001b[39;49m\u001b[43m \u001b[49m\u001b[43martist_id\u001b[49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mid\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvalues\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\n\u001b[0;32m 5\u001b[0m artist_top_tracks \u001b[38;5;241m=\u001b[39m get_top_tracks(artist_id)\n\u001b[0;32m 6\u001b[0m artist_top_tracks[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124martist_name\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m artist_name\n", + "\u001b[1;31mIndexError\u001b[0m: index 0 is out of bounds for axis 0 with size 0" + ] + } + ], + "source": [ + "playlist = make_playlist(related_artists_df[[\"id\"]]) # Asegúrate de seleccionar solo la columna 'id'\n", + "playlist.head(30)" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "id": "ab9285b4", + "metadata": {}, + "outputs": [], + "source": [ + "# Dummy code\n", + "\n", + "def get_top_tracks(artist_id):\n", + " resource = \"artists\"\n", + " parameters = f\"/{artist_id}/top-tracks?market=ES\"\n", + " url = base_url + resource + parameters \n", + " response = requests.get(url, headers=header_info).json()\n", + " df_tracks = pd.DataFrame(response[\"tracks\"])[[\"id\", \"href\", \"name\", \"uri\"]]\n", + " return df_tracks" + ] + }, + { + "cell_type": "markdown", + "id": "77edd0b5", + "metadata": {}, + "source": [ + "### Checkpoint" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f78f8267", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 131, + "id": "51426ff7", + "metadata": {}, + "outputs": [], + "source": [ + "artist_id = '0L8ExT028jH3ddEcZwqJJ5'" + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "id": "a27b7ab5", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'url' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[132], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# API call\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m artist_response \u001b[38;5;241m=\u001b[39m requests\u001b[38;5;241m.\u001b[39mget(\u001b[43murl\u001b[49m, headers\u001b[38;5;241m=\u001b[39mheader_info)\n\u001b[0;32m 3\u001b[0m artist_response\u001b[38;5;241m.\u001b[39mstatus_code\n", + "\u001b[1;31mNameError\u001b[0m: name 'url' is not defined" + ] + } + ], + "source": [ + "# API call\n", + "artist_response = requests.get(url, headers=header_info)\n", + "artist_response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "af3d275f", + "metadata": {}, + "outputs": [], + "source": [ + "# Create DataFrames\n", + "artist_df = pd.DataFrame(dict_artist)\n", + "artist_df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d0b7a58", + "metadata": {}, + "outputs": [], + "source": [ + "method = '/related-artists'\n", + "# argument = \"market = ES\"\n", + "full_endpoint = base_url + resource + parameters + method \n", + "print(full_endpoint)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "761dbc46", + "metadata": {}, + "outputs": [], + "source": [ + "related_artists_response = requests.get(full_endpoint, headers = header_info)\n", + "related_artists_response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4830ee02", + "metadata": {}, + "outputs": [], + "source": [ + "related_artists_json = related_artists_response.json()\n", + "related_artists_json" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd4e105c", + "metadata": {}, + "outputs": [], + "source": [ + "#Ahora voy a sacar los artistas relacionados con sus id.\n", + "def get_related_artists(artist_id):\n", + " parameters = f\"/{artist_id}/related-artists\"\n", + " url = base_url + resource + parameters\n", + " response = related_artists_json\n", + " df_related_artists= pd.DataFrame(response[\"artists\"])[[\"id\", \"name\"]]\n", + " df_related_artists\n", + " return df_related_artists" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "92a27aff", + "metadata": {}, + "outputs": [], + "source": [ + "df_related_artists = get_related_artists('0L8ExT028jH3ddEcZwqJJ5')\n", + "df_related_artists" + ] + }, + { + "cell_type": "markdown", + "id": "0a4e08b8", + "metadata": {}, + "source": [ + "### 3. Top-tracks" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f542ab9b", + "metadata": {}, + "outputs": [], + "source": [ + "# Voy a coger los top_tracks de mi artista seleccionado:\n", + "\n", + "def top_tracks(artist_id):\n", + " resource = \"artists\"\n", + " parameters = f\"/{artist_id}/top-tracks?market=ES\"\n", + " url = base_url + resource + parameters\n", + " response = requests.get(url, headers=header_info).json()\n", + " df_tracks = pd.DataFrame(response[\"tracks\"])[[\"id\", \"href\", \"name\", \"uri\"]]\n", + " return df_top_tracks" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "45ad08ca", + "metadata": {}, + "outputs": [], + "source": [ + "def make_playlist(dataframe):\n", + " playlist = pd.DataFrame() \n", + " for artist_id in dataframe:\n", + " artist_name = df_related_artists[df_related_artists[\"id\"] == artist_id][\"name\"].values[0]\n", + " top_tracks = top_tracks(artist_id)\n", + " top_tracks[\"artist_name\"] = artist_name\n", + " playlist = pd.concat([playlist, top_tracks])\n", + " playlist = playlist.reset_index(drop=True)\n", + " return playlist" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3155e199", + "metadata": {}, + "outputs": [], + "source": [ + "playlist = make_playlist(df_related_artists[\"id\"])\n", + "playlist.head(20)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c10359c3", + "metadata": {}, + "outputs": [], + "source": [ + "'''Para mas tarde'''\n", + "\n", + "# # Rename columns\n", + "# related_artists_df = related_artists_df.rename(columns={'id':'related_id',\n", + "# 'name':'related_name',\n", + "# 'genres':'related_genres',\n", + "# 'popularity': 'popularity',\n", + "# 'followers':'related_followers'\n", + "# })\n", + "# related_artists_df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f5966220", + "metadata": {}, + "outputs": [], + "source": [ + "print(artist_df.columns)" + ] + }, + { + "cell_type": "markdown", + "id": "11cbe450", + "metadata": {}, + "source": [ + "### 2. Top-tracks" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a1854027", + "metadata": {}, + "outputs": [], + "source": [ + "# Get top tracks\n", + "method = '/top-tracks'\n", + "argument = '?market=ES'\n", + "full_endpoint = base_url + resource + parameters + method + argument\n", + "full_endpoint" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cde6a3c8", + "metadata": {}, + "outputs": [], + "source": [ + "def get_top_tracks(artist_id):\n", + " resource = \"artists\"\n", + " parameters = f\"/{artist_id}/top-tracks?market=ES\"\n", + " url = base_url + resource + parameters\n", + " response = requests.get(url, headers=header_info).json()\n", + " df_tracks = pd.DataFrame(response[\"tracks\"])[[\"id\", \"href\", \"name\", \"uri\"]]\n", + " return df_tracks" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6f61482e", + "metadata": {}, + "outputs": [], + "source": [ + "get_top_tracks(\"0L8ExT028jH3ddEcZwqJJ5\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ffbf563", + "metadata": {}, + "outputs": [], + "source": [ + "top_tracks_response = requests.get(full_endpoint, headers = header_info)\n", + "top_tracks_response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "050efac3", + "metadata": {}, + "outputs": [], + "source": [ + "top_tracks_json = top_tracks_response.json()\n", + "top_tracks_json.keys()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "38a5547d", + "metadata": {}, + "outputs": [], + "source": [ + "dict_top_tracks = dict((key, [top_tracks_json[key]]) for key in ['tracks'] if key in top_tracks_json)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e298cd66", + "metadata": {}, + "outputs": [], + "source": [ + "dict_top_tracks" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "03760a1a", + "metadata": {}, + "outputs": [], + "source": [ + "# Top Tracks\n", + "[top_tracks_json['tracks'][i]['name'] for i in range(len(top_tracks_json['tracks']))]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "772e1d54", + "metadata": {}, + "outputs": [], + "source": [ + "# Create DataFrames\n", + "top_tracks_df = pd.DataFrame(top_tracks_json['tracks'])[['id','name']]\n", + "top_tracks_df['tracks'] = artist_id\n", + "top_tracks_df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5910eed8", + "metadata": {}, + "outputs": [], + "source": [ + "print(artist_df.columns)\n", + "print(top_tracks_df.columns)" + ] + }, + { + "cell_type": "markdown", + "id": "b0de1f10", + "metadata": {}, + "source": [ + "### 3. Related artists" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6f29a8d9", + "metadata": {}, + "outputs": [], + "source": [ + "# Get Related artists\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3c890e5e", + "metadata": {}, + "outputs": [], + "source": [ + "related_artists_response = requests.get(full_endpoint, headers = header_info)\n", + "related_artists_response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "516b044a", + "metadata": {}, + "outputs": [], + "source": [ + "related_artists_json = related_artists_response.json()\n", + "related_artists_json" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fdcd1b96", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "# Related Artists\n", + "[related_artists_json['artists'][i]['name'] for i in range(len(related_artists_json['artists']))]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b6faa31a", + "metadata": {}, + "outputs": [], + "source": [ + "# Create DataFrames\n", + "related_artists_df = pd.DataFrame(related_artists_json['artists'])[['id','name','genres','popularity','followers']]\n", + "related_artists_df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "76fd9618", + "metadata": {}, + "outputs": [], + "source": [ + "# # Rename columns\n", + "# related_artists_df = related_artists_df.rename(columns={'id':'related_id',\n", + "# 'name':'related_name',\n", + "# 'genres':'related_genres',\n", + "# 'popularity': 'popularity',\n", + "# 'followers':'related_followers'\n", + "# })\n", + "# related_artists_df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bf88e803", + "metadata": {}, + "outputs": [], + "source": [ + "def make_playlist(dataframe):\n", + " playlist = pd.DataFrame() \n", + " for artist_df in dataframe:\n", + " artist_name = related_artists_df[related_artists_df[\"id\"] == artist_df][\"name\"].values[0]\n", + " top_tracks = top_tracks_df[\"id\"]\n", + " top_tracks[\"name\"] = artist_name\n", + " playlist = pd.concat([playlist, top_tracks])\n", + " playlist = playlist.reset_index(drop=True)\n", + " return playlist\n", + "make_playlist(related_artists_df)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8d1f3639", + "metadata": {}, + "outputs": [], "source": [ "# Add a column with selected id artist\n", "related_artists_df['artist_id'] = artist_id\n", @@ -2099,24 +3029,10 @@ }, { "cell_type": "code", - "execution_count": 965, + "execution_count": null, "id": "0451ecf4", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Index(['related_id', 'related_name', 'related_genres', 'popularity',\n", - " 'related_followers', 'artist_id'],\n", - " dtype='object')\n", - "Index(['external_urls', 'followers', 'genres', 'href', 'id', 'images', 'name',\n", - " 'popularity', 'type', 'uri', 'artist_id'],\n", - " dtype='object')\n", - "Index(['id', 'href', 'name', 'uri', 'tracks'], dtype='object')\n" - ] - } - ], + "outputs": [], "source": [ "print(related_artists_df.columns)\n", "print(artist_df.columns)\n", @@ -2150,30 +3066,11 @@ }, { "cell_type": "code", - "execution_count": 967, + "execution_count": null, "id": "3ae8c65e", "metadata": {}, - "outputs": [ - { - "ename": "KeyError", - "evalue": "'related_id'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_14984\\2131523432.py\u001b[0m in \u001b[0;36m?\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mplaylist_df\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmerge\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrelated_artists_df\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtop_tracks_df\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mon\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'related_id'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mplaylist_df\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\site-packages\\pandas\\core\\reshape\\merge.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)\u001b[0m\n\u001b[0;32m 144\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mbool\u001b[0m \u001b[1;33m|\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 145\u001b[0m \u001b[0mindicator\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[1;33m|\u001b[0m \u001b[0mbool\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 146\u001b[0m \u001b[0mvalidate\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[1;33m|\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 147\u001b[0m ) -> DataFrame:\n\u001b[1;32m--> 148\u001b[1;33m op = _MergeOperation(\n\u001b[0m\u001b[0;32m 149\u001b[0m \u001b[0mleft\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 150\u001b[0m \u001b[0mright\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 151\u001b[0m \u001b[0mhow\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mhow\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\site-packages\\pandas\\core\\reshape\\merge.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(self, left, right, how, on, left_on, right_on, axis, left_index, right_index, sort, suffixes, indicator, validate)\u001b[0m\n\u001b[0;32m 733\u001b[0m (\n\u001b[0;32m 734\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mleft_join_keys\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 735\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mright_join_keys\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 736\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjoin_names\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 737\u001b[1;33m ) = self._get_merge_keys()\n\u001b[0m\u001b[0;32m 738\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 739\u001b[0m \u001b[1;31m# validate the merge keys dtypes. We may need to coerce\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 740\u001b[0m \u001b[1;31m# to avoid incompatible dtypes\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\site-packages\\pandas\\core\\reshape\\merge.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1199\u001b[0m \u001b[1;31m# Then we're either Hashable or a wrong-length arraylike,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1200\u001b[0m \u001b[1;31m# the latter of which will raise\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1201\u001b[0m \u001b[0mrk\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcast\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mHashable\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrk\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1202\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mrk\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1203\u001b[1;33m \u001b[0mright_keys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mright\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_label_or_level_values\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrk\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1204\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1205\u001b[0m \u001b[1;31m# work-around for merge_asof(right_index=True)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1206\u001b[0m \u001b[0mright_keys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mright\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\m1_env\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m 1774\u001b[0m \u001b[0mvalues\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mxs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mother_axes\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_values\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1775\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_is_level_reference\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1776\u001b[0m \u001b[0mvalues\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maxes\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_level_values\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_values\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1777\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1778\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1779\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1780\u001b[0m \u001b[1;31m# Check for duplicates\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1781\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mvalues\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mKeyError\u001b[0m: 'related_id'" - ] - } - ], - "source": [ - "playlist_df = pd.merge(related_artists_df, top_tracks_df, on='related_id')\n", - "playlist_df" - ] + "outputs": [], + "source": [] }, { "cell_type": "markdown", @@ -2205,7 +3102,10 @@ "outputs": [], "source": [ "# Bonus\n", - "\n", + "import json\n", + "import string\n", + "import random\n", + "import base64\n", "\n" ] },