library(tidyverse)
library(readr)
library(dplyr)Week 1 Assignment - Loading Data into a Data Frame
Global Music Streaming Analysis
Approach
For this assignment, I chose a dataset from Kaggle containing information on music streaming across different platforms such as Spotify, Apple Music, Tidal, and many more. The dataset contains 12 features which include, the user’s main streaming platform, most played artist, how often they repeat a song, when they usually stream a song, and similar features.
My plan for this assignment is to practice loading the data into R, renaming columns, transform column types if it is incorrect, such as a numerical column needs to be a categorical column or vice versa.
Data Sources:
I chose this data source because I have passion for music and as I was deciding what dataset I want to do my first assignment on, I was listening to music in the moment and it became clear that I should do something music related.
Codebase
Loading in the Data
raw_data <- read.csv("https://raw.githubusercontent.com/HaiderrX/CUNY-SPS-MSDS/refs/heads/main/DATA607/Week%201%20-%20Environment%20Setup%3B%20Basic%20Operations/Global_Music_Streaming_Listener_Preferences.csv")glimpse(raw_data)Rows: 5,000
Columns: 12
$ User_ID <chr> "U1000", "U1001", "U1002", "U…
$ Age <int> 34, 24, 49, 55, 13, 25, 49, 3…
$ Country <chr> "Japan", "Germany", "Germany"…
$ Streaming.Platform <chr> "Tidal", "Deezer", "Deezer", …
$ Top.Genre <chr> "Reggae", "Country", "Pop", "…
$ Minutes.Streamed.Per.Day <int> 295, 86, 363, 348, 30, 536, 5…
$ Number.of.Songs.Liked <int> 138, 388, 368, 349, 328, 243,…
$ Most.Played.Artist <chr> "Adele", "Ed Sheeran", "Post …
$ Subscription.Type <chr> "Free", "Premium", "Premium",…
$ Listening.Time..Morning.Afternoon.Night. <chr> "Afternoon", "Night", "Aftern…
$ Discover.Weekly.Engagement.... <dbl> 47.42, 12.06, 47.19, 31.27, 3…
$ Repeat.Song.Rate.... <dbl> 16.74, 69.25, 67.38, 76.51, 4…
There are 5000 rows with 12 features in this dataset as mentioned. In it contains user information and music statistics.
However this dataset needs to have suitable column names.
df_rename <- raw_data %>%
rename(
'user_id' = User_ID,
'age'= Age,
'country' = Country,
'streaming_platform' = Streaming.Platform,
'top_genre' = Top.Genre,
'daily_streamed_minutes' = Minutes.Streamed.Per.Day,
'songs_liked_count' = Number.of.Songs.Liked,
'most_played_artist' = Most.Played.Artist,
'subscription' = Subscription.Type,
'listening_time'= Listening.Time..Morning.Afternoon.Night.,
'discover_weekly_engagement_rate' = Discover.Weekly.Engagement....,
'songs_repeated_rate' = Repeat.Song.Rate....
)colnames(df_rename) [1] "user_id" "age"
[3] "country" "streaming_platform"
[5] "top_genre" "daily_streamed_minutes"
[7] "songs_liked_count" "most_played_artist"
[9] "subscription" "listening_time"
[11] "discover_weekly_engagement_rate" "songs_repeated_rate"
glimpse(df_rename)Rows: 5,000
Columns: 12
$ user_id <chr> "U1000", "U1001", "U1002", "U1003", "U…
$ age <int> 34, 24, 49, 55, 13, 25, 49, 32, 25, 37…
$ country <chr> "Japan", "Germany", "Germany", "Austra…
$ streaming_platform <chr> "Tidal", "Deezer", "Deezer", "YouTube"…
$ top_genre <chr> "Reggae", "Country", "Pop", "Reggae", …
$ daily_streamed_minutes <int> 295, 86, 363, 348, 30, 536, 547, 98, 5…
$ songs_liked_count <int> 138, 388, 368, 349, 328, 243, 70, 448,…
$ most_played_artist <chr> "Adele", "Ed Sheeran", "Post Malone", …
$ subscription <chr> "Free", "Premium", "Premium", "Premium…
$ listening_time <chr> "Afternoon", "Night", "Afternoon", "Mo…
$ discover_weekly_engagement_rate <dbl> 47.42, 12.06, 47.19, 31.27, 30.68, 70.…
$ songs_repeated_rate <dbl> 16.74, 69.25, 67.38, 76.51, 43.41, 27.…
After renaming the columns to more appropriate names, the next task was to check for column types if they were incorrect. However upon inspection, it was not necessary as it seems the columns were the correct types with the given data.
Then lastly, to create a subset of the data that are relevant for analysis
clean_data <- df_rename |>
select(
user_id,
age,
country,
top_genre,
most_played_artist,
streaming_platform,
daily_streamed_minutes,
songs_liked_count
)glimpse(clean_data)Rows: 5,000
Columns: 8
$ user_id <chr> "U1000", "U1001", "U1002", "U1003", "U1004", "U…
$ age <int> 34, 24, 49, 55, 13, 25, 49, 32, 25, 37, 40, 43,…
$ country <chr> "Japan", "Germany", "Germany", "Australia", "Ge…
$ top_genre <chr> "Reggae", "Country", "Pop", "Reggae", "Reggae",…
$ most_played_artist <chr> "Adele", "Ed Sheeran", "Post Malone", "Dua Lipa…
$ streaming_platform <chr> "Tidal", "Deezer", "Deezer", "YouTube", "Amazon…
$ daily_streamed_minutes <int> 295, 86, 363, 348, 30, 536, 547, 98, 526, 514, …
$ songs_liked_count <int> 138, 388, 368, 349, 328, 243, 70, 448, 27, 299,…
These 8 features create a clear picture for what a listener’s demographic and listening habits contain.
Conclusion
For future work, I plan to do an exploratory data analysis, visualizations that compare the counts of streaming platforms in this dataset, as well as a most played artist bar graph. Following that I would do a machine learning prediction of top genre.
Given that this dataset has 5000 rows, in the future I would like to have a dataset where it contains more information to give a bigger sense as this dataset may have its limitations.