Skip to content

Instantly share code, notes, and snippets.

@MartinWeiss12
Last active December 17, 2022 05:34
Show Gist options
  • Save MartinWeiss12/39a76ed233a0b7f917e4769c9b90057e to your computer and use it in GitHub Desktop.
Save MartinWeiss12/39a76ed233a0b7f917e4769c9b90057e to your computer and use it in GitHub Desktop.
Top Albums
topAlbumsDf = pd.DataFrame(columns = ['Rank', 'Album', 'Streams'])
topAlbums = []
albumList = data['Album'].tolist()
for i in range(50): #change to see different number of top albums
def most_frequent(albumList):
return max(set(albumList), key = albumList.count)
topAlbum = most_frequent(albumList)
topAlbumsDf = topAlbumsDf.append({'Rank': i+1, 'Album': topAlbum,
'Streams': albumList.count(topAlbum)}, ignore_index = True)
topAlbums.append(topAlbum)
albumList = [i for i in albumList if i != topAlbum]
display(topAlbumsDf.to_string(index = False))
topAlbumsDf.to_excel(f'{outputPath}/spotify_top_albums.xlsx', index = False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment