diff --git a/notebooks/spotify_rest_api_challenge.ipynb b/notebooks/spotify_rest_api_challenge.ipynb
index 5e4f8f7..1f6899e 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": 33,
"id": "17a49776",
"metadata": {},
"outputs": [],
"source": [
"# Imports\n",
- "\n",
- "\n"
+ "import pandas as pd\n",
+ "import requests\n",
+ "import numpy as np"
]
},
{
@@ -38,7 +39,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 34,
"id": "7b5d2e52",
"metadata": {},
"outputs": [],
@@ -52,7 +53,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 35,
"id": "c7901d1e",
"metadata": {},
"outputs": [],
@@ -64,10 +65,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"id": "262e7e18",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "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": [
"access_token = auth_response['access_token']\n",
"auth_response"
@@ -85,7 +98,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 37,
"id": "62e6d4fb",
"metadata": {},
"outputs": [],
@@ -93,11 +106,31 @@
"# 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": 2,
+ "id": "a293e6e7",
+ "metadata": {},
+ "outputs": [
+ {
+ "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": [
+ "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,31 +174,2912 @@
"---"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "7e14c0df",
+ "metadata": {},
+ "source": [
+ "# Borrador"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "69fd5c14",
+ "metadata": {},
+ "source": [
+ "### 1. Artist chosen (Option 1):\n",
+ "\n",
+ "#### Red Hot Chili Peppers - Give it away\n",
+ "\n",
+ ""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "id": "d54ece25",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "https://api.spotify.com/v1/\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(base_url)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "id": "7ae72cfb",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "https://api.spotify.com/v1/artists/0L8ExT028jH3ddEcZwqJJ5\n"
+ ]
+ }
+ ],
+ "source": [
+ "artist_id = '0L8ExT028jH3ddEcZwqJJ5'\n",
+ "resource = 'artists/'\n",
+ "\n",
+ "# Artist endpoint\n",
+ "artist_ep = base_url + resource + artist_id\n",
+ "print(artist_ep)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "id": "abb5e6d2",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "200"
+ ]
+ },
+ "execution_count": 23,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# API call\n",
+ "artist_response = requests.get(artist_ep, headers=header_info)\n",
+ "artist_response.status_code"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "id": "2b230721",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'external_urls': {'spotify': 'https://open.spotify.com/artist/0L8ExT028jH3ddEcZwqJJ5'},\n",
+ " 'followers': {'href': None, 'total': 20275607},\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": 24,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "artist_response = artist_response.json()\n",
+ "artist_response"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "a47636b0",
+ "metadata": {},
+ "source": [
+ "### 2. Artist top tracks"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "id": "cf77327e",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Artist DataFrame:\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " id | \n",
+ " href | \n",
+ " name | \n",
+ " uri | \n",
+ " artist_name | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 0L8ExT028jH3ddEcZwqJJ5 | \n",
+ " https://open.spotify.com/artist/0L8ExT028jH3dd... | \n",
+ " Red Hot Chili Peppers | \n",
+ " spotify:artist:0L8ExT028jH3ddEcZwqJJ5 | \n",
+ " Red Hot Chili Peppers | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " id href \\\n",
+ "0 0L8ExT028jH3ddEcZwqJJ5 https://open.spotify.com/artist/0L8ExT028jH3dd... \n",
+ "\n",
+ " name uri \\\n",
+ "0 Red Hot Chili Peppers spotify:artist:0L8ExT028jH3ddEcZwqJJ5 \n",
+ "\n",
+ " artist_name \n",
+ "0 Red Hot Chili Peppers "
+ ]
+ },
+ "execution_count": 25,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 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": 29,
+ "id": "03583915",
+ "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': 87,\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': 84,\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': 82,\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': 81,\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/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': 77,\n",
+ " 'preview_url': 'https://p.scdn.co/mp3-preview/e0c62e6fb378167d40ab941124f9ed7b9911a35e?cid=bec9dd918ed04aca96b6eb3c699e443f',\n",
+ " 'track_number': 9,\n",
+ " 'type': 'track',\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",
+ " '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'}]}"
+ ]
+ },
+ "execution_count": 29,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "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": 30,
+ "id": "e9cf4def",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Top Tracks DataFrame:\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " id | \n",
+ " href | \n",
+ " song_name | \n",
+ " uri | \n",
+ " artist_name | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 3d9DChrdc6BOeFsbrZ3Is0 | \n",
+ " https://api.spotify.com/v1/tracks/3d9DChrdc6BO... | \n",
+ " Under the Bridge | \n",
+ " spotify:track:3d9DChrdc6BOeFsbrZ3Is0 | \n",
+ " Red Hot Chili Peppers | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 48UPSzbZjgc449aqz8bxox | \n",
+ " https://api.spotify.com/v1/tracks/48UPSzbZjgc4... | \n",
+ " Californication | \n",
+ " spotify:track:48UPSzbZjgc449aqz8bxox | \n",
+ " Red Hot Chili Peppers | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3ZOEytgrvLwQaqXreDs2Jx | \n",
+ " https://api.spotify.com/v1/tracks/3ZOEytgrvLwQ... | \n",
+ " Can't Stop | \n",
+ " spotify:track:3ZOEytgrvLwQaqXreDs2Jx | \n",
+ " Red Hot Chili Peppers | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 1G391cbiT3v3Cywg8T7DM1 | \n",
+ " https://api.spotify.com/v1/tracks/1G391cbiT3v3... | \n",
+ " Scar Tissue | \n",
+ " spotify:track:1G391cbiT3v3Cywg8T7DM1 | \n",
+ " Red Hot Chili Peppers | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 64BbK9SFKH2jk86U3dGj2P | \n",
+ " https://api.spotify.com/v1/tracks/64BbK9SFKH2j... | \n",
+ " Otherside | \n",
+ " spotify:track:64BbK9SFKH2jk86U3dGj2P | \n",
+ " Red Hot Chili Peppers | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 2aibwv5hGXSgw7Yru8IYTO | \n",
+ " https://api.spotify.com/v1/tracks/2aibwv5hGXSg... | \n",
+ " Snow (Hey Oh) | \n",
+ " spotify:track:2aibwv5hGXSgw7Yru8IYTO | \n",
+ " Red Hot Chili Peppers | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 10Nmj3JCNoMeBQ87uw5j8k | \n",
+ " https://api.spotify.com/v1/tracks/10Nmj3JCNoMe... | \n",
+ " Dani California | \n",
+ " spotify:track:10Nmj3JCNoMeBQ87uw5j8k | \n",
+ " Red Hot Chili Peppers | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 1f2V8U1BiWaC9aJWmpOARe | \n",
+ " https://api.spotify.com/v1/tracks/1f2V8U1BiWaC... | \n",
+ " By the Way | \n",
+ " spotify:track:1f2V8U1BiWaC9aJWmpOARe | \n",
+ " Red Hot Chili Peppers | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 0uppYCG86ajpV2hSR3dJJ0 | \n",
+ " https://api.spotify.com/v1/tracks/0uppYCG86ajp... | \n",
+ " Give It Away | \n",
+ " spotify:track:0uppYCG86ajpV2hSR3dJJ0 | \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",
+ "
"
+ ],
+ "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 0uppYCG86ajpV2hSR3dJJ0 https://api.spotify.com/v1/tracks/0uppYCG86ajp... \n",
+ "9 2oaK4JLVnmRGIO9ytBE1bt https://api.spotify.com/v1/tracks/2oaK4JLVnmRG... \n",
+ "\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",
+ "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 Give It Away spotify:track:0uppYCG86ajpV2hSR3dJJ0 \n",
+ "9 Dark Necessities spotify:track:2oaK4JLVnmRGIO9ytBE1bt \n",
+ "\n",
+ " 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": 30,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "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",
+ "# 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": 31,
+ "id": "148436e2",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/7jy3rLJdDQY21OgRLCZ9sD'},\n",
+ " 'followers': {'href': None, 'total': 11382646},\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': 5680557},\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': 4317543},\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': 8469091},\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': 4773525},\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': 18453988},\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': 4182235},\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': 3140865},\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': 5246913},\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': 3362302},\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': 4781549},\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': 14430221},\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': 13858412},\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': 9787143},\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': 6427068},\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': 3373292},\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': 7894134},\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': 2941525},\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': 5442508},\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': 13908224},\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": 31,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "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": 14,
+ "id": "43aedba0",
+ "metadata": {},
+ "outputs": [
+ {
+ "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": [
+ "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": 33,
+ "id": "e2058344",
+ "metadata": {},
+ "outputs": [
+ {
+ "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": [
+ "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": 16,
+ "id": "2c994d0b",
+ "metadata": {},
+ "outputs": [
+ {
+ "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": [
+ "# 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": 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",
+ " id | \n",
+ " href | \n",
+ " name | \n",
+ " uri | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 3d9DChrdc6BOeFsbrZ3Is0 | \n",
+ " https://api.spotify.com/v1/tracks/3d9DChrdc6BO... | \n",
+ " Under the Bridge | \n",
+ " spotify:track:3d9DChrdc6BOeFsbrZ3Is0 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 48UPSzbZjgc449aqz8bxox | \n",
+ " https://api.spotify.com/v1/tracks/48UPSzbZjgc4... | \n",
+ " Californication | \n",
+ " spotify:track:48UPSzbZjgc449aqz8bxox | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3ZOEytgrvLwQaqXreDs2Jx | \n",
+ " https://api.spotify.com/v1/tracks/3ZOEytgrvLwQ... | \n",
+ " Can't Stop | \n",
+ " spotify:track:3ZOEytgrvLwQaqXreDs2Jx | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 1G391cbiT3v3Cywg8T7DM1 | \n",
+ " https://api.spotify.com/v1/tracks/1G391cbiT3v3... | \n",
+ " Scar Tissue | \n",
+ " spotify:track:1G391cbiT3v3Cywg8T7DM1 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 64BbK9SFKH2jk86U3dGj2P | \n",
+ " https://api.spotify.com/v1/tracks/64BbK9SFKH2j... | \n",
+ " Otherside | \n",
+ " spotify:track:64BbK9SFKH2jk86U3dGj2P | \n",
+ "
\n",
+ " \n",
+ "
\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": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " id | \n",
+ " name | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 7jy3rLJdDQY21OgRLCZ9sD | \n",
+ " Foo Fighters | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2d0hyoQ5ynDBnkvAbJKORj | \n",
+ " Rage Against The Machine | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 2ziB7fzrXBoh1HUPS6sVFn | \n",
+ " Audioslave | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 1w5Kfo2jwwIPruYS2UWh56 | \n",
+ " Pearl Jam | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 40Yq4vzPs9VNUrIBG5Jr2i | \n",
+ " The Smashing Pumpkins | \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": [
+ " 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": 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": "04f85940",
+ "id": "761dbc46",
"metadata": {},
"outputs": [],
"source": [
- "# Here you can complete your endpoint URI\n",
+ "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",
- "full_endpoint = \n",
- "full_endpoint"
+ "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": "50ec3959",
+ "id": "3155e199",
"metadata": {},
"outputs": [],
"source": [
- "# Start building your playlist!!!\n",
+ "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",
+ "related_artists_df.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "0451ecf4",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(related_artists_df.columns)\n",
+ "print(artist_df.columns)\n",
+ "print(top_tracks_df.columns)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "dadd9205",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Join artist and related artist to merge info\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": null,
+ "id": "3ae8c65e",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "id": "87f28353",
+ "metadata": {},
+ "source": [
+ "# Checkpoint"
+ ]
+ },
{
"cell_type": "markdown",
"id": "98827be6",
@@ -188,7 +3102,10 @@
"outputs": [],
"source": [
"# Bonus\n",
- "\n",
+ "import json\n",
+ "import string\n",
+ "import random\n",
+ "import base64\n",
"\n"
]
},
@@ -209,21 +3126,13 @@
"\n",
""
]
- },
- {
- "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 +3144,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.11"
+ "version": "3.10.13"
}
},
"nbformat": 4,