Created
June 24, 2024 02:12
-
-
Save timbennett/a417adb513903a41a71cd5c0ec7b1f2f to your computer and use it in GitHub Desktop.
Find top artists/tracks you've listened to within the past year but not the past 90 days
This file contains hidden or 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
# Find top artists/tracks you've listened to within the past year but not the past 90 days | |
# Before starting, download your Last.fm history from here: https://benjaminbenben.com/lastfm-to-csv/ | |
import datetime | |
import pandas as pd | |
# add column names (at time of publishing, the site above didn't do this) | |
df = pd.read_csv("username.csv",header=0,names=["artist","album","title","timestamp"]) | |
df.timestamp = pd.to_datetime(df.timestamp) | |
df['trackid'] = df['artist']+df['title'] | |
# create list of tracks played in past 90 days, and between 365 and 90 days ago | |
last90days = df[df.timestamp > datetime.datetime.now() - pd.to_timedelta("90day")] | |
last365to90days = df[(df.timestamp < datetime.datetime.now() - pd.to_timedelta("90day")) & (df.timestamp > datetime.datetime.now() - pd.to_timedelta("365day"))] | |
# create a filter for lapsed ARTISTS | |
lapsed_artists = last365to90days[~last365to90days['artist'].isin(last90days.artist)] | |
# create a filter for lapsed ARTIST-TITLE PAIRS | |
lapsed_titles = last365to90days[~last365to90days['trackid'].isin(last90days['trackid'])] | |
# results | |
lapsed_artists['artist'].value_counts().head(50) | |
lapsed_titles[['artist','title']].value_counts().head(50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment