Last active
December 17, 2022 05:34
-
-
Save MartinWeiss12/39a76ed233a0b7f917e4769c9b90057e to your computer and use it in GitHub Desktop.
Top Albums
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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