6/15/2023 0 Comments Lastfm scrobbler apiOne more important note – Notice in the screenshot above the dates show the first six days of October. ),0) # If the artist has changed, reset this value to 0 MAX(E2:E3) # If it has changed, set it to the higher value IF(E3=E2, # Check if the count variable changed from the previous rowį2, # If it hasn't changed, the max is the same as it was before Let’s break it down step by step: =IF(B3=B2, # Only if the artist doesn't change I added a column entitled maxcount to hold the highest the count has reached for that artist. ![]() Once I had the data in Excel, preparing it didn’t take too long. Write.csv(allArtistsAllDates, file = "allArtistsAllDates.csv") # Get every artist name and all dates/monthIDs My data contained 3,425 different artists and 124 months, so this new dataframe was 424,700 rows long (3,425*124). I wanted an entry for every artist, every month. I started by taking a list of every artist, every date, and every monthID in the data and combined them in a new dataframe. If you can suggest a way to do this in R please let me know. My solution for this is pretty inelegant, and required me to take the data into Excel as I couldn’t work it out in R. This meant in our animation they were present (top, even) in month 31, absent in month 32, and top again in month 33. Ideally the count variable for month 32 for Red Hot Chili Peppers would read 2560, the same as the previous month they were present. RHCP did not receive any plays in August 2012, monthID 32. Here is a snapshot of the total play count for the Red Hot Chili Peppers over a few months. One that I didn’t find until I created an animation and bars were jumping all over the place. # 3.3 split date into year and month columns Having one column for each will be helpful later on. Now, let’s split our date up into year and month. If we use the head() function to call a specific artist, we’ll see their songs in order of when they were listened to, and the count increasing by one for each play. Count keeps the running total for the number of plays an artist has. Now we have one more column in our dataframe. This will download your listening history as a dataframe. Store your details as variables and plug them into the download_scrobbles() function from scrobbler. Just sign in to last.fm, go to their dev site, and request an API key. I used the R package called scrobbler to get my data. The code for this post can be found on my github page. I decided my listening history was the perfect data to learn how to create a bar chart race. I’ve been playing around with some APIs for the first time lately and thought I’d check out the Last.fm one. I say still, I’m one of the few who ever had one. ![]() I’m one of the few people that actually still has – and uses – a Last.fm account.
0 Comments
Leave a Reply. |