{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Importing the libraries" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import pandas as pd\n", "import numpy as np\n", "import json\n", "import spotipy\n", "import spotipy.oauth2 as oauth2\n", "from spotipy.oauth2 import SpotifyOAuth,SpotifyClientCredentials\n", "import yaml\n", "import re\n", "from tqdm import tqdm\n", "import multiprocessing as mp\n", "import time\n", "import random\n", "import datetime\n", "import pickle\n", "from sklearn.feature_extraction.text import TfidfVectorizer\n", "from sklearn.metrics.pairwise import cosine_similarity\n", "from sklearn.preprocessing import MinMaxScaler\n", "import matplotlib.pyplot as plt\n", "from skimage import io\n", "from sklearn.preprocessing import OneHotEncoder" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "stream= open(\"spotify/spotify.yaml\")\n", "spotify_details = yaml.safe_load(stream)\n", "auth_manager = SpotifyClientCredentials(client_id=spotify_details['Client_id'],\n", " client_secret=spotify_details['client_secret'])\n", "sp = spotipy.client.Spotify(auth_manager=auth_manager)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Importing the dataset" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "dtypes = {'track_uri': 'object', 'artist_uri': 'object', 'album_uri': 'object', 'danceability': 'float16', 'energy': 'float16', 'key': 'float16',\n", " 'loudness': 'float16', 'mode': 'float16', 'speechiness': 'float16', 'acousticness': 'float16', 'instrumentalness': 'float16',\n", " 'liveness': 'float16', 'valence': 'float16', 'tempo': 'float16', 'duration_ms': 'float32', 'time_signature': 'float16',\n", " 'Track_release_date': 'int8', 'Track_pop': 'int8', 'Artist_pop': 'int8', 'Artist_genres': 'object'}\n", "try:\n", " df=pd.read_csv('Data/1M_unique_processed_data_grow.csv',dtype=dtypes)\n", "except:\n", " print('Failed to load grow')\n", " df=pd.read_csv('Data/1M_unique_processed_data.csv',dtype=dtypes)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Test" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Extract playlist tracks and artist uri" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "80\n", "80\n" ] } ], "source": [ "def get_IDs (user, playlist_id):\n", " track_ids = []\n", " artist_id = []\n", " playlist=sp.user_playlist (user, playlist_id)\n", " for item in playlist['tracks']['items']:\n", " track=item['track']\n", " track_ids.append(track['id'])\n", " artist=item['track']['artists']\n", " artist_id.append(artist[0]['id'])\n", " return track_ids,artist_id\n", "\n", "\n", "track_ids,artist_id = get_IDs ('Ruby', 'spotify:playlist:37i9dQZF1DX8FwnYE6PRvL') \n", "print (len(track_ids))\n", "print (len(artist_id))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "getting the unique URI and repeating the extraction features and preprocessing steps for the user's playlist (input)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "artist_id_uni=list(set(artist_id))\n", "track_ids_uni=list(set(track_ids))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 4/4 [00:00<00:00, 12.20it/s]\n" ] } ], "source": [ "audio_features=pd.DataFrame()\n", "for i in tqdm(range(0,len(track_ids_uni),25)):\n", " try:\n", " track_feature = sp.audio_features(track_ids_uni[i:i+25])\n", " track_df = pd.DataFrame(track_feature)\n", " audio_features=pd.concat([audio_features,track_df],axis=0)\n", " except Exception as e:\n", " print(e)\n", " continue" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 4/4 [00:00<00:00, 4.37it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "list index out of range\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "track_=pd.DataFrame()\n", "for i in tqdm(range(0,len(track_ids_uni),25)):\n", " try:\n", " track_features = sp.tracks(track_ids_uni[i:i+25])\n", " for x in range(25):\n", " track_pop=pd.DataFrame([track_ids_uni[i+x]],columns=['Track_uri'])\n", " track_pop['Track_release_date']=track_features['tracks'][x]['album']['release_date']\n", " track_pop['Track_pop'] = track_features['tracks'][x][\"popularity\"]\n", " track_pop['Artist_uri']=track_features['tracks'][x]['artists'][0]['id']\n", " track_pop['Album_uri']=track_features['tracks'][x]['album']['id']\n", " track_=pd.concat([track_,track_pop],axis=0)\n", " except Exception as e:\n", " print(e)\n", " continue" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 3/3 [00:00<00:00, 9.76it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "list index out of range\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "artist_=pd.DataFrame()\n", "for i in tqdm(range(0,len(artist_id_uni),25)):\n", " try:\n", " artist_features = sp.artists(artist_id_uni[i:i+25])\n", " for x in range(25):\n", " artist_df=pd.DataFrame([artist_id_uni[i+x]],columns=['Artist_uri'])\n", " artist_pop = artist_features['artists'][x][\"popularity\"]\n", " artist_genres = artist_features['artists'][x][\"genres\"]\n", " artist_df[\"Artist_pop\"] = artist_pop\n", " if artist_genres: \n", " artist_df[\"genres\"] = \" \".join([re.sub(' ','_',i) for i in artist_genres])\n", " else:\n", " artist_df[\"genres\"] = \"unknown\"\n", " artist_=pd.concat([artist_,artist_df],axis=0)\n", " except Exception as e:\n", " print(e)\n", " continue" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "test=pd.DataFrame(track_,columns=['Track_uri','Artist_uri','Album_uri'])" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "test.rename(columns = {'Track_uri':'track_uri','Artist_uri':'artist_uri','Album_uri':'album_uri'}, inplace = True)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "audio_features.drop(columns=['type','uri','track_href','analysis_url'],axis=1,inplace=True)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "test = pd.merge(test,audio_features, left_on = \"track_uri\", right_on= \"id\",how = 'outer')\n", "test = pd.merge(test,track_, left_on = \"track_uri\", right_on= \"Track_uri\",how = 'outer')\n", "test = pd.merge(test,artist_, left_on = \"artist_uri\", right_on= \"Artist_uri\",how = 'outer')" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "del audio_features,track_,artist_" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "test.rename(columns = {'genres':'Artist_genres'}, inplace = True)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "test.drop(columns=['Track_uri','Artist_uri_x','Artist_uri_y','Album_uri','id'],axis=1,inplace=True)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "test.dropna(axis=0,inplace=True)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "test['Track_pop'] = test['Track_pop'].apply(lambda x: int(x/5))\n", "test['Artist_pop'] = test['Artist_pop'].apply(lambda x: int(x/5))\n", "test['Track_release_date'] = test['Track_release_date'].apply(lambda x: x.split('-')[0])\n", "test['Track_release_date']=test['Track_release_date'].astype('int16')\n", "test['Track_release_date'] = test['Track_release_date'].apply(lambda x: int(x/50))" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "test[['danceability', 'energy', 'key','loudness', 'mode', 'speechiness', 'acousticness', 'instrumentalness','liveness', 'valence', 'tempo', 'time_signature']]=test[['danceability', 'energy', 'key','loudness', 'mode', 'speechiness', 'acousticness', 'instrumentalness','liveness', 'valence', 'tempo','time_signature']].astype('float16')\n", "test[['duration_ms']]=test[['duration_ms']].astype('float32')\n", "test[['Track_release_date', 'Track_pop', 'Artist_pop']]=test[['Track_release_date', 'Track_pop', 'Artist_pop']].astype('int8')" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "currentdf=len(df)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "df=pd.concat([df,test],axis=0)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "df.drop_duplicates(subset=['track_uri'],inplace=True,keep='last') ## keep last to keep the dataset updated " ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "df.dropna(axis=0,inplace=True)" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "36 New Tracks Found\n" ] } ], "source": [ "print('{} New Tracks Found'.format(len(df)-currentdf))" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "36 New Found\n" ] } ], "source": [ "#saving the tracks if they weren't found in the dataset\n", "if len(df)>currentdf: \n", " df.to_csv('data/1M_unique_processed_data_grow.csv',index=False)\n", " print('{} New Found'.format(len(df)-currentdf))\n", " streamlit=df[df.Track_pop >0] # dropped track with 0 popularity score to save space and ram for the final model\n", " streamlit.to_csv('data/streamlit.csv',index=False)\n", " del streamlit" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "df = df[~df['track_uri'].isin(test['track_uri'].values)]" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "test['Artist_genres'] = test['Artist_genres'].apply(lambda x: x.split(\" \"))\n", "tfidf = TfidfVectorizer(max_features=3) #max_features=5 \n", "tfidf_matrix = tfidf.fit_transform(test['Artist_genres'].apply(lambda x: \" \".join(x)))\n", "genre_df = pd.DataFrame(tfidf_matrix.toarray())\n", "genre_df.columns = ['genre' + \"|\" + i for i in tfidf.get_feature_names_out()]" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "genre_df=genre_df.astype('float16')\n", "test.drop(columns=['Artist_genres'],axis=1,inplace=True)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "test = pd.concat([test.reset_index(drop=True), genre_df.reset_index(drop=True)],axis = 1)\n" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test.isna().sum().sum()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# df" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "df['Artist_genres'] = df['Artist_genres'].apply(lambda x: x.split(\" \"))\n", "tfidf_matrix = tfidf.transform(df['Artist_genres'].apply(lambda x: \" \".join(x)))\n", "genre_df = pd.DataFrame(tfidf_matrix.toarray())\n", "genre_df.columns = ['genre' + \"|\" + i for i in tfidf.get_feature_names_out()]" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [], "source": [ "genre_df=genre_df.astype('float16')\n", "df.drop(columns=['Artist_genres'],axis=1,inplace=True)" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "df = pd.concat([df.reset_index(drop=True), genre_df.reset_index(drop=True)],axis = 1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# pred" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "genre|unknown not found\n" ] } ], "source": [ "try:\n", " df.drop(columns=['genre|unknown'],axis=1,inplace=True)\n", " test.drop(columns=['genre|unknown'],axis=1,inplace=True)\n", "except:\n", " print('genre|unknown not found')" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['track_uri', 'artist_uri', 'album_uri', 'danceability', 'energy', 'key',\n", " 'loudness', 'mode', 'speechiness', 'acousticness', 'instrumentalness',\n", " 'liveness', 'valence', 'tempo', 'duration_ms', 'time_signature',\n", " 'Track_release_date', 'Track_pop', 'Artist_pop', 'genre|modern_rock',\n", " 'genre|permanent_wave', 'genre|rock'],\n", " dtype='object')" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test.columns" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['track_uri', 'artist_uri', 'album_uri', 'danceability', 'energy', 'key',\n", " 'loudness', 'mode', 'speechiness', 'acousticness', 'instrumentalness',\n", " 'liveness', 'valence', 'tempo', 'duration_ms', 'time_signature',\n", " 'Track_release_date', 'Track_pop', 'Artist_pop', 'genre|modern_rock',\n", " 'genre|permanent_wave', 'genre|rock'],\n", " dtype='object')" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.columns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "I was first using OneHotEncoder for \"Track_release_date\", \"Track_pop\", and \"Artist_pop,\" but I found no difference in the final result other than high memory usage." ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\" ohe = OneHotEncoder(handle_unknown='ignore')\\ndummies = pd.DataFrame(ohe.fit_transform(test[['Track_release_date', 'Track_pop', 'Artist_pop']]).toarray(), index=test.index,dtype=int)\\ncolumn_name = ohe.get_feature_names_out(['Track_release_date', 'Track_pop', 'Artist_pop'])\\ndummies.columns=column_name\\ntest = pd.concat([test.drop(['Track_release_date', 'Track_pop', 'Artist_pop'], axis=1), dummies], axis=1) \"" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"\"\" ohe = OneHotEncoder(handle_unknown='ignore')\n", "dummies = pd.DataFrame(ohe.fit_transform(test[['Track_release_date', 'Track_pop', 'Artist_pop']]).toarray(), index=test.index,dtype=int)\n", "column_name = ohe.get_feature_names_out(['Track_release_date', 'Track_pop', 'Artist_pop'])\n", "dummies.columns=column_name\n", "test = pd.concat([test.drop(['Track_release_date', 'Track_pop', 'Artist_pop'], axis=1), dummies], axis=1) \"\"\"" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\" ohe2 = OneHotEncoder(categories=ohe.categories_,handle_unknown='ignore')\\ndummies = pd.DataFrame(ohe2.fit_transform(df[['Track_release_date', 'Track_pop', 'Artist_pop']]).toarray(), index=df.index, dtype=int)\\ncolumn_name = ohe2.get_feature_names_out(['Track_release_date', 'Track_pop', 'Artist_pop'])\\ndummies.columns=column_name\\ndf=pd.concat([df.drop(['Track_release_date', 'Track_pop', 'Artist_pop'], axis=1), dummies], axis=1)\\n \"" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"\"\" ohe2 = OneHotEncoder(categories=ohe.categories_,handle_unknown='ignore')\n", "dummies = pd.DataFrame(ohe2.fit_transform(df[['Track_release_date', 'Track_pop', 'Artist_pop']]).toarray(), index=df.index, dtype=int)\n", "column_name = ohe2.get_feature_names_out(['Track_release_date', 'Track_pop', 'Artist_pop'])\n", "dummies.columns=column_name\n", "df=pd.concat([df.drop(['Track_release_date', 'Track_pop', 'Artist_pop'], axis=1), dummies], axis=1)\n", " \"\"\"" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "#df.info(memory_usage = \"deep\")" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "#test.loc[:,test.columns.str.startswith('genre')]=test.loc[:,test.columns.str.startswith('genre')].astype('bool')\n", "#df.loc[:,df.columns.str.startswith('genre')]=df.loc[:,df.columns.str.startswith('genre')].astype('bool')\n" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "sc=MinMaxScaler()\n", "df.iloc[:,3:19]=sc.fit_transform(df.iloc[:,3:19])\n", "pickle.dump(sc, open('data/sc.sav', 'wb'))" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "test.iloc[:,3:19]=sc.transform(test.iloc[:,3:19])" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
track_uriartist_urialbum_uridanceabilityenergykeyloudnessmodespeechinessacousticness...valencetempoduration_mstime_signatureTrack_release_dateTrack_popArtist_popgenre|modern_rockgenre|permanent_wavegenre|rock
02AT8iROs4FQueDv2c8q2KE69uxyAqqPIsUyTO8txoP2M37...7Ln80lUS6He07XvHI8qqHH4gzpq5DPGxSnKTe4SA8HAU58...78bpIziExqiI9qztvNFlQu3cfAM8b8KqJRoIzt3zLKqw0k...44.13823866.6279336.36363766.57518457.05.7619254.38462...51.55395538.8822522.99902264.00000178.95000167.77777756.65000116.45312517.187543.09375
\n", "

1 rows × 22 columns

\n", "
" ], "text/plain": [ " track_uri \\\n", "0 2AT8iROs4FQueDv2c8q2KE69uxyAqqPIsUyTO8txoP2M37... \n", "\n", " artist_uri \\\n", "0 7Ln80lUS6He07XvHI8qqHH4gzpq5DPGxSnKTe4SA8HAU58... \n", "\n", " album_uri danceability energy \\\n", "0 78bpIziExqiI9qztvNFlQu3cfAM8b8KqJRoIzt3zLKqw0k... 44.138238 66.62793 \n", "\n", " key loudness mode speechiness acousticness ... valence \\\n", "0 36.363637 66.575184 57.0 5.761925 4.38462 ... 51.553955 \n", "\n", " tempo duration_ms time_signature Track_release_date Track_pop \\\n", "0 38.882252 2.999022 64.000001 78.950001 67.777777 \n", "\n", " Artist_pop genre|modern_rock genre|permanent_wave genre|rock \n", "0 56.650001 16.453125 17.1875 43.09375 \n", "\n", "[1 rows x 22 columns]" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "playvec=pd.DataFrame(test.sum(axis=0)).T\n", "playvec" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0track_nameartist_name
00Don't Stop Me Now - Remastered 2011Queen
01Another One Bites The Dust - Remastered 2011Queen
02It's My LifeBon Jovi
03Can You Feel My HeartBring Me The Horizon
04Sweet Child O' MineGuns N' Roses
05Welcome To The JungleGuns N' Roses
06Highway to HellAC/DC
07Can't Help Falling in LoveElvis Presley
08Have You Ever Seen The RainCreedence Clearwater Revival
09Fortunate SonCreedence Clearwater Revival
010Dreams - 2004 RemasterFleetwood Mac
011Dream OnAerosmith
012Change (In the House of Flies)Deftones
013Under Pressure - Remastered 2011Queen
014Crazy Little Thing Called Love - Remastered 2011Queen
015We Will Rock You - Remastered 2011Queen
016T.N.T.AC/DC
017Suspicious MindsElvis Presley
018Paradise CityGuns N' Roses
019Hotel California - 2013 RemasterEagles
020AfricaTOTO
021Go Your Own Way - 2004 RemasterFleetwood Mac
022We Didn't Start the FireBilly Joel
023Uptown GirlBilly Joel
024Take It Easy - 2013 RemasterEagles
025Freak On a LeashKorn
026Everywhere - 2017 RemasterFleetwood Mac
027My Own Summer (Shove It)Deftones
028Another Brick in the Wall, Pt. 2Pink Floyd
029CrazyAerosmith
030ViennaBilly Joel
031Be Quiet and Drive (Far Away)Deftones
032Wish You Were HerePink Floyd
033Stairway to Heaven - RemasterLed Zeppelin
034LandslideFleetwood Mac
035Rock N Roll TrainAC/DC
036The Rock Showblink-182
037I Miss Youblink-182
038Bulls On ParadeRage Against The Machine
039Man in the BoxAlice In Chains
040Brown Eyed GirlVan Morrison
041You Make My Dreams (Come True)Daryl Hall & John Oates
042Free BirdLynyrd Skynyrd
043Hold the LineTOTO
044Mrs. Robinson - From \"The Graduate\" SoundtrackSimon & Garfunkel
045Stand by MeBen E. King
046Sweet Dreams (Are Made of This) - RemasteredEurythmics
047Cherry WavesDeftones
048RosemaryDeftones
049It's a Long Way to the Top (If You Wanna Rock ...AC/DC
\n", "
" ], "text/plain": [ " 0 track_name \\\n", "0 0 Don't Stop Me Now - Remastered 2011 \n", "0 1 Another One Bites The Dust - Remastered 2011 \n", "0 2 It's My Life \n", "0 3 Can You Feel My Heart \n", "0 4 Sweet Child O' Mine \n", "0 5 Welcome To The Jungle \n", "0 6 Highway to Hell \n", "0 7 Can't Help Falling in Love \n", "0 8 Have You Ever Seen The Rain \n", "0 9 Fortunate Son \n", "0 10 Dreams - 2004 Remaster \n", "0 11 Dream On \n", "0 12 Change (In the House of Flies) \n", "0 13 Under Pressure - Remastered 2011 \n", "0 14 Crazy Little Thing Called Love - Remastered 2011 \n", "0 15 We Will Rock You - Remastered 2011 \n", "0 16 T.N.T. \n", "0 17 Suspicious Minds \n", "0 18 Paradise City \n", "0 19 Hotel California - 2013 Remaster \n", "0 20 Africa \n", "0 21 Go Your Own Way - 2004 Remaster \n", "0 22 We Didn't Start the Fire \n", "0 23 Uptown Girl \n", "0 24 Take It Easy - 2013 Remaster \n", "0 25 Freak On a Leash \n", "0 26 Everywhere - 2017 Remaster \n", "0 27 My Own Summer (Shove It) \n", "0 28 Another Brick in the Wall, Pt. 2 \n", "0 29 Crazy \n", "0 30 Vienna \n", "0 31 Be Quiet and Drive (Far Away) \n", "0 32 Wish You Were Here \n", "0 33 Stairway to Heaven - Remaster \n", "0 34 Landslide \n", "0 35 Rock N Roll Train \n", "0 36 The Rock Show \n", "0 37 I Miss You \n", "0 38 Bulls On Parade \n", "0 39 Man in the Box \n", "0 40 Brown Eyed Girl \n", "0 41 You Make My Dreams (Come True) \n", "0 42 Free Bird \n", "0 43 Hold the Line \n", "0 44 Mrs. Robinson - From \"The Graduate\" Soundtrack \n", "0 45 Stand by Me \n", "0 46 Sweet Dreams (Are Made of This) - Remastered \n", "0 47 Cherry Waves \n", "0 48 Rosemary \n", "0 49 It's a Long Way to the Top (If You Wanna Rock ... \n", "\n", " artist_name \n", "0 Queen \n", "0 Queen \n", "0 Bon Jovi \n", "0 Bring Me The Horizon \n", "0 Guns N' Roses \n", "0 Guns N' Roses \n", "0 AC/DC \n", "0 Elvis Presley \n", "0 Creedence Clearwater Revival \n", "0 Creedence Clearwater Revival \n", "0 Fleetwood Mac \n", "0 Aerosmith \n", "0 Deftones \n", "0 Queen \n", "0 Queen \n", "0 Queen \n", "0 AC/DC \n", "0 Elvis Presley \n", "0 Guns N' Roses \n", "0 Eagles \n", "0 TOTO \n", "0 Fleetwood Mac \n", "0 Billy Joel \n", "0 Billy Joel \n", "0 Eagles \n", "0 Korn \n", "0 Fleetwood Mac \n", "0 Deftones \n", "0 Pink Floyd \n", "0 Aerosmith \n", "0 Billy Joel \n", "0 Deftones \n", "0 Pink Floyd \n", "0 Led Zeppelin \n", "0 Fleetwood Mac \n", "0 AC/DC \n", "0 blink-182 \n", "0 blink-182 \n", "0 Rage Against The Machine \n", "0 Alice In Chains \n", "0 Van Morrison \n", "0 Daryl Hall & John Oates \n", "0 Lynyrd Skynyrd \n", "0 TOTO \n", "0 Simon & Garfunkel \n", "0 Ben E. King \n", "0 Eurythmics \n", "0 Deftones \n", "0 Deftones \n", "0 AC/DC " ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df['sim']=cosine_similarity(df.drop(['track_uri', 'artist_uri', 'album_uri'], axis = 1),playvec.drop(['track_uri', 'artist_uri', 'album_uri'], axis = 1))\n", "df['sim2']=cosine_similarity(df.iloc[:,16:-1],playvec.iloc[:,16:])\n", "df['sim3']=cosine_similarity(df.iloc[:,19:-2],playvec.iloc[:,19:])\n", "df = df.sort_values(['sim3','sim2','sim'],ascending = False,kind='stable')\n", "qq=df.groupby('artist_uri').head(5).track_uri.head(50) #to limit recmmendation by same artist\n", "aa=sp.tracks(qq[0:50])\n", "Fresult=pd.DataFrame()\n", "for i in range(50):\n", " result=pd.DataFrame([i])\n", " result['track_name']=aa['tracks'][i]['name']\n", " result['artist_name']=aa['tracks'][i]['artists'][0]['name']\n", " #result['url']=aa['tracks'][i]['external_urls']['spotify']\n", " #result['image']=aa['tracks'][i]['album']['images'][1]['url']\n", " Fresult=pd.concat([Fresult,result],axis=0)\n", "Fresult" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0track_nameartist_name
00Go Your Own Way - 2004 RemasterFleetwood Mac
01We Didn't Start the FireBilly Joel
02Gimme All Your Lovin'ZZ Top
03Thorn in My Side - RemasteredEurythmics
04Any Way You Want ItJourney
05I Don't Wanna StopOzzy Osbourne
06Semi-Charmed LifeThird Eye Blind
07Sweet Child O' MineGuns N' Roses
08Old Time Rock & RollBob Seger
09LumpThe Presidents Of The United States Of America
010Run-AroundBlues Traveler
011Kyouran Hey Kids!!THE ORAL CIGARETTES
012We're Not Gonna Take ItTwisted Sister
013Legs - 2008 RemasterZZ Top
014Highway TuneGreta Van Fleet
015Sharp Dressed Man - 2008 RemasterZZ Top
016Owner of a Lonely HeartYes
017Mighty Wings - From \"Top Gun\" Original SoundtrackCheap Trick
018Living After MidnightJudas Priest
019I Believe in a Thing Called LoveThe Darkness
020Dance the Night Away - 2015 RemasterVan Halen
021Pink HousesJohn Mellencamp
022How I Could Just Kill a ManRage Against The Machine
023Stiff Upper LipAC/DC
024More Than ThisRoxy Music
025Black Smoke RisingGreta Van Fleet
026We're An American Band - Remastered 2002Grand Funk Railroad
027Never Let You Go - 2008 RemasterThird Eye Blind
028White Wedding - Pt. 1Billy Idol
029Hey TonightCreedence Clearwater Revival
030Shot in the DarkOzzy Osbourne
031Rock And Roll Never ForgetsBob Seger
032Peace of MindBoston
033Carry on Wayward SonKansas
034Hollywood NightsBob Seger
035Against The WindBob Seger
036Bad MedicineBon Jovi
037Have A Nice DayBon Jovi
038Touch Too MuchAC/DC
039Come UndoneDuran Duran
040All I Wanna Do Is Make Love To YouHeart
041No ExcusesAlice In Chains
042Walk This WayAerosmith
043Two PrincesSpin Doctors
044Girls on Film - 2010 RemasterDuran Duran
045Jamie's Cryin' - 2015 RemasterVan Halen
046Who Says You Can't Go HomeBon Jovi
047Anna MollyIncubus
048Ace of SpadesMotörhead
049Fallen Angel - RemasteredPoison
\n", "
" ], "text/plain": [ " 0 track_name \\\n", "0 0 Go Your Own Way - 2004 Remaster \n", "0 1 We Didn't Start the Fire \n", "0 2 Gimme All Your Lovin' \n", "0 3 Thorn in My Side - Remastered \n", "0 4 Any Way You Want It \n", "0 5 I Don't Wanna Stop \n", "0 6 Semi-Charmed Life \n", "0 7 Sweet Child O' Mine \n", "0 8 Old Time Rock & Roll \n", "0 9 Lump \n", "0 10 Run-Around \n", "0 11 Kyouran Hey Kids!! \n", "0 12 We're Not Gonna Take It \n", "0 13 Legs - 2008 Remaster \n", "0 14 Highway Tune \n", "0 15 Sharp Dressed Man - 2008 Remaster \n", "0 16 Owner of a Lonely Heart \n", "0 17 Mighty Wings - From \"Top Gun\" Original Soundtrack \n", "0 18 Living After Midnight \n", "0 19 I Believe in a Thing Called Love \n", "0 20 Dance the Night Away - 2015 Remaster \n", "0 21 Pink Houses \n", "0 22 How I Could Just Kill a Man \n", "0 23 Stiff Upper Lip \n", "0 24 More Than This \n", "0 25 Black Smoke Rising \n", "0 26 We're An American Band - Remastered 2002 \n", "0 27 Never Let You Go - 2008 Remaster \n", "0 28 White Wedding - Pt. 1 \n", "0 29 Hey Tonight \n", "0 30 Shot in the Dark \n", "0 31 Rock And Roll Never Forgets \n", "0 32 Peace of Mind \n", "0 33 Carry on Wayward Son \n", "0 34 Hollywood Nights \n", "0 35 Against The Wind \n", "0 36 Bad Medicine \n", "0 37 Have A Nice Day \n", "0 38 Touch Too Much \n", "0 39 Come Undone \n", "0 40 All I Wanna Do Is Make Love To You \n", "0 41 No Excuses \n", "0 42 Walk This Way \n", "0 43 Two Princes \n", "0 44 Girls on Film - 2010 Remaster \n", "0 45 Jamie's Cryin' - 2015 Remaster \n", "0 46 Who Says You Can't Go Home \n", "0 47 Anna Molly \n", "0 48 Ace of Spades \n", "0 49 Fallen Angel - Remastered \n", "\n", " artist_name \n", "0 Fleetwood Mac \n", "0 Billy Joel \n", "0 ZZ Top \n", "0 Eurythmics \n", "0 Journey \n", "0 Ozzy Osbourne \n", "0 Third Eye Blind \n", "0 Guns N' Roses \n", "0 Bob Seger \n", "0 The Presidents Of The United States Of America \n", "0 Blues Traveler \n", "0 THE ORAL CIGARETTES \n", "0 Twisted Sister \n", "0 ZZ Top \n", "0 Greta Van Fleet \n", "0 ZZ Top \n", "0 Yes \n", "0 Cheap Trick \n", "0 Judas Priest \n", "0 The Darkness \n", "0 Van Halen \n", "0 John Mellencamp \n", "0 Rage Against The Machine \n", "0 AC/DC \n", "0 Roxy Music \n", "0 Greta Van Fleet \n", "0 Grand Funk Railroad \n", "0 Third Eye Blind \n", "0 Billy Idol \n", "0 Creedence Clearwater Revival \n", "0 Ozzy Osbourne \n", "0 Bob Seger \n", "0 Boston \n", "0 Kansas \n", "0 Bob Seger \n", "0 Bob Seger \n", "0 Bon Jovi \n", "0 Bon Jovi \n", "0 AC/DC \n", "0 Duran Duran \n", "0 Heart \n", "0 Alice In Chains \n", "0 Aerosmith \n", "0 Spin Doctors \n", "0 Duran Duran \n", "0 Van Halen \n", "0 Bon Jovi \n", "0 Incubus \n", "0 Motörhead \n", "0 Poison " ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df['sim']=cosine_similarity(df.iloc[:,3:16],playvec.iloc[:,3:16])\n", "df['sim2']=cosine_similarity(df.loc[:, df.columns.str.startswith('T')|df.columns.str.startswith('A')],playvec.loc[:, playvec.columns.str.startswith('T')|playvec.columns.str.startswith('A')])\n", "df['sim3']=cosine_similarity(df.loc[:, df.columns.str.startswith('genre')],playvec.loc[:, playvec.columns.str.startswith('genre')])\n", "df['sim4']=(df['sim']+df['sim2']+df['sim3'])/3\n", "df = df.sort_values(['sim4'],ascending = False,kind='stable')\n", "# genra>audio>pop\n", "qq=df.groupby('artist_uri').head(5).track_uri.head(50)\n", "aa=sp.tracks(qq[0:50])\n", "Fresult=pd.DataFrame()\n", "for i in range(50):\n", " result=pd.DataFrame([i])\n", " result['track_name']=aa['tracks'][i]['name']\n", " result['artist_name']=aa['tracks'][i]['artists'][0]['name']\n", " #result['url']=aa['tracks'][i]['external_urls']['spotify']\n", " #result['image']=aa['tracks'][i]['album']['images'][1]['url']\n", " Fresult=pd.concat([Fresult,result],axis=0)\n", "Fresult" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0track_nameartist_name
01R.O.C.K. In The U.S.A. (A Salute To 60's Rock)John Mellencamp
02Blood On BloodBon Jovi
03T.N.T.AC/DC
04WarningGreen Day
05Turn The PageMetallica
06Forever NowGreen Day
07DualitySlipknot
08Lit UpBuckcherry
09Plug in BabyMuse
010Wheel in the SkyJourney
011Start Me Up - Remastered 2009The Rolling Stones
012I Was Made For Lovin' YouKISS
013Since You've Been GoneThe Outfield
014ERAThe Faim
015King Of Wishful ThinkingNew Found Glory
016PMA (feat. Pale Waves)All Time Low
017Re-Education (Through Labor)Rise Against
018SituationsEscape the Fate
019LostCharlotte Sands
020Way AwayYellowcard
021Way AwayYellowcard
022Can't Fight This FeelingREO Speedwagon
023Rock AmericaDanger Danger
024Until the Day I DieStory Of The Year
025Where Is My Mind? - RemasteredPixies
026You Don't Mess Around with JimJim Croce
027ManeaterDaryl Hall & John Oates
028The PriceTwisted Sister
029Heartbreaker - 1990 RemasterLed Zeppelin
030The Hardest Button to ButtonThe White Stripes
031Ain't Talkin' 'Bout Love - 2015 RemasterVan Halen
032Where Is My Mind? - RemasteredPixies
033All Systems GoBox Car Racer
034May 16Lagwagon
035Creepin Up The Backstairs - Composite Edit (do...The Fratellis
036AnimalNeon Trees
037Watch The WorldBox Car Racer
038All My FaultFenix TX
039Pork And BeansWeezer
040Mixtape 2003The Academic
0411+1Scouting For Girls
042Be StillThe Killers
043Only The HorsesScissor Sisters
044Mardy BumArctic Monkeys
045Blue OrchidThe White Stripes
046Holy Wars...The Punishment Due - RemasteredMegadeth
047Lucifer SamPink Floyd
048What Is and What Should Never Be - 29/6/69 Top...Led Zeppelin
049Peace of MindBoston
050AlivePearl Jam
\n", "
" ], "text/plain": [ " 0 track_name \\\n", "0 1 R.O.C.K. In The U.S.A. (A Salute To 60's Rock) \n", "0 2 Blood On Blood \n", "0 3 T.N.T. \n", "0 4 Warning \n", "0 5 Turn The Page \n", "0 6 Forever Now \n", "0 7 Duality \n", "0 8 Lit Up \n", "0 9 Plug in Baby \n", "0 10 Wheel in the Sky \n", "0 11 Start Me Up - Remastered 2009 \n", "0 12 I Was Made For Lovin' You \n", "0 13 Since You've Been Gone \n", "0 14 ERA \n", "0 15 King Of Wishful Thinking \n", "0 16 PMA (feat. Pale Waves) \n", "0 17 Re-Education (Through Labor) \n", "0 18 Situations \n", "0 19 Lost \n", "0 20 Way Away \n", "0 21 Way Away \n", "0 22 Can't Fight This Feeling \n", "0 23 Rock America \n", "0 24 Until the Day I Die \n", "0 25 Where Is My Mind? - Remastered \n", "0 26 You Don't Mess Around with Jim \n", "0 27 Maneater \n", "0 28 The Price \n", "0 29 Heartbreaker - 1990 Remaster \n", "0 30 The Hardest Button to Button \n", "0 31 Ain't Talkin' 'Bout Love - 2015 Remaster \n", "0 32 Where Is My Mind? - Remastered \n", "0 33 All Systems Go \n", "0 34 May 16 \n", "0 35 Creepin Up The Backstairs - Composite Edit (do... \n", "0 36 Animal \n", "0 37 Watch The World \n", "0 38 All My Fault \n", "0 39 Pork And Beans \n", "0 40 Mixtape 2003 \n", "0 41 1+1 \n", "0 42 Be Still \n", "0 43 Only The Horses \n", "0 44 Mardy Bum \n", "0 45 Blue Orchid \n", "0 46 Holy Wars...The Punishment Due - Remastered \n", "0 47 Lucifer Sam \n", "0 48 What Is and What Should Never Be - 29/6/69 Top... \n", "0 49 Peace of Mind \n", "0 50 Alive \n", "\n", " artist_name \n", "0 John Mellencamp \n", "0 Bon Jovi \n", "0 AC/DC \n", "0 Green Day \n", "0 Metallica \n", "0 Green Day \n", "0 Slipknot \n", "0 Buckcherry \n", "0 Muse \n", "0 Journey \n", "0 The Rolling Stones \n", "0 KISS \n", "0 The Outfield \n", "0 The Faim \n", "0 New Found Glory \n", "0 All Time Low \n", "0 Rise Against \n", "0 Escape the Fate \n", "0 Charlotte Sands \n", "0 Yellowcard \n", "0 Yellowcard \n", "0 REO Speedwagon \n", "0 Danger Danger \n", "0 Story Of The Year \n", "0 Pixies \n", "0 Jim Croce \n", "0 Daryl Hall & John Oates \n", "0 Twisted Sister \n", "0 Led Zeppelin \n", "0 The White Stripes \n", "0 Van Halen \n", "0 Pixies \n", "0 Box Car Racer \n", "0 Lagwagon \n", "0 The Fratellis \n", "0 Neon Trees \n", "0 Box Car Racer \n", "0 Fenix TX \n", "0 Weezer \n", "0 The Academic \n", "0 Scouting For Girls \n", "0 The Killers \n", "0 Scissor Sisters \n", "0 Arctic Monkeys \n", "0 The White Stripes \n", "0 Megadeth \n", "0 Pink Floyd \n", "0 Led Zeppelin \n", "0 Boston \n", "0 Pearl Jam " ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Spotifyresult=pd.DataFrame()\n", "for i in range(len(test)-1):\n", " if len(Spotifyresult)>=50:\n", " break\n", " ff=sp.recommendations(seed_tracks=list(test.track_uri[1+i:5+i]),limit=2)\n", " for z in range(2):\n", " result=pd.DataFrame([z+(2*i)+1])\n", " result['track_name']=ff['tracks'][z]['name']\n", " result['artist_name']=ff['tracks'][z]['artists'][0]['name']\n", " #result['uri']=ff['tracks'][z]['id']\n", " #result['url']=ff['tracks'][z]['external_urls']['spotify']\n", " #result['image']=ff['tracks'][z]['album']['images'][1]['url']\n", " Spotifyresult=pd.concat([Spotifyresult,result],axis=0)\n", "Spotifyresult" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "sorry ur playlist must have atleast 5 tracks for this method to work" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.13 ('base')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "e246d2215c418239c9316a1ebf2d8abb44dc50b2e5b0e29defd87143398aa387" } } }, "nbformat": 4, "nbformat_minor": 2 }