R Notebook by Miguel Miranda Enriquez
Data source: Kaggle
suppressWarnings(suppressMessages(library(dplyr)))
suppressWarnings(suppressMessages(library(tidyverse)))
df = read.csv("C:\\Users\\mmira\\Downloads\\SpotifyFeatures.csv")
colnames(df)
## [1] "genre" "artist_name" "track_name" "track_id"
## [5] "popularity" "acousticness" "danceability" "duration_ms"
## [9] "energy" "instrumentalness" "key" "liveness"
## [13] "loudness" "mode" "speechiness" "tempo"
## [17] "time_signature" "valence"
#Merge Children's Music and Children`s Music genre
df$genre[df$genre == "Children's Music"] <- "Children’s Music"
#Remove music genres: A Capella, Anime, Children’s Music,
# Classical, Comedy, Movie, Opera, Soundtrack
df <- df[df$genre != "A Capella" & df$genre != "Anime" &
df$genre != "Children’s Music" &
df$genre != "Classical" & df$genre != "Comedy" &
df$genre != "Movie" & df$genre != "Opera" &
df$genre != "Soundtrack",]
head(df)
genre <chr> | artist_name <chr> | track_name <chr> | ||
---|---|---|---|---|
136 | R&B | Mary J. Blige | Be Without You - Kendu Mix | |
137 | R&B | Rihanna | Desperado | |
138 | R&B | Yung Bleu | Ice On My Baby (feat. Kevin Gates) - Remix | |
139 | R&B | Surfaces | Heaven Falls / Fall on Me | |
140 | R&B | Olivia O'Brien | Love Myself | |
141 | R&B | ELHAE | Needs |
#Remove duplicates and
# create list of multiple genre values in one cell
new_df <- aggregate(df[1], by = df[4],
FUN = unique)
head(new_df)
track_id <chr> | genre <list> | |||
---|---|---|---|---|
1 | 000DfZJww8KiixTKuk9usJ | <chr [1]> | ||
2 | 000EWWBkYaREzsBplYjUag | <chr [1]> | ||
3 | 000xQL6tZNLJzIrtIgxqSl | <chr [2]> | ||
4 | 001bQcMKt86oNbnWne4EAB | <chr [1]> | ||
5 | 001CyR8xqmmpVZFiTZJ5BC | <chr [1]> | ||
6 | 001gDjxhKGDSx4sMMAgS9R | <chr [1]> |
#Sort each list using str_sort function from tidyverse package
new_df$genre <- sapply(new_df$genre, str_sort)
#Change list to string
new_df$genre <- sapply(new_df$genre, paste, collapse=",")
head(new_df)
track_id <chr> | genre <chr> | |||
---|---|---|---|---|
1 | 000DfZJww8KiixTKuk9usJ | Reggae | ||
2 | 000EWWBkYaREzsBplYjUag | Jazz | ||
3 | 000xQL6tZNLJzIrtIgxqSl | Dance,Pop | ||
4 | 001bQcMKt86oNbnWne4EAB | Reggaeton | ||
5 | 001CyR8xqmmpVZFiTZJ5BC | Blues | ||
6 | 001gDjxhKGDSx4sMMAgS9R | Rock |
#Merge dataframes by performing left inner join using dplyr package
#Drop old genre column
dropped_df = df[,!(names(df)
%in%c("genre"))]
#Merge new genre column
new_df = new_df %>% inner_join(dropped_df,
by="track_id")
#Remove duplicates
new_df = new_df %>% distinct()
head(new_df)
track_id <chr> | genre <chr> | artist_name <chr> | track_name <chr> | popularity <int> | ||
---|---|---|---|---|---|---|
1 | 000DfZJww8KiixTKuk9usJ | Reggae | Mike Love | Earthlings | 30 | |
2 | 000EWWBkYaREzsBplYjUag | Jazz | Don Philippe | Fewerdolr | 39 | |
3 | 000xQL6tZNLJzIrtIgxqSl | Dance,Pop | ZAYN | Still Got Time | 70 | |
4 | 001bQcMKt86oNbnWne4EAB | Reggaeton | Justin Quiles | No Quieren Que Gane | 41 | |
5 | 001CyR8xqmmpVZFiTZJ5BC | Blues | Taj Mahal | She Knows How To Rock Me | 31 | |
6 | 001gDjxhKGDSx4sMMAgS9R | Rock | Young Tribe | Kingdom | 58 |
new_df
track_id <chr> | genre <chr> | |
---|---|---|
000DfZJww8KiixTKuk9usJ | Reggae | |
000EWWBkYaREzsBplYjUag | Jazz | |
000xQL6tZNLJzIrtIgxqSl | Dance,Pop | |
001bQcMKt86oNbnWne4EAB | Reggaeton | |
001CyR8xqmmpVZFiTZJ5BC | Blues | |
001gDjxhKGDSx4sMMAgS9R | Rock | |
001ifh9Zkyc5DhK7AGQRtK | Folk,Indie | |
001KkOBeRiQ1J7IEJYHODW | World | |
001YQlnDSduXd5LgBd66gT | Ska | |
002opcRBgYV5jqoh72QcqA | Dance,Pop |
# Use mutate funtion to create dummy variables based on if the genre title is contained in the all_genre column
#To avoid using special characters in column names...
# Column name for R&B is RnB
spotify_data <- new_df %>% mutate(
Pop = ifelse(grepl("Pop", genre, fixed = TRUE) == TRUE, 1, 0),
Rap = ifelse(grepl("Rap", genre, fixed = TRUE) == TRUE, 1, 0),
Rock = ifelse(grepl("Rock", genre, fixed = TRUE) == TRUE, 1, 0),
Hip_Hop = ifelse(grepl("Hip-Hop", genre, fixed = TRUE) == TRUE, 1, 0),
Dance = ifelse(grepl("Dance", genre, fixed = TRUE) == TRUE, 1, 0),
Indie = ifelse(grepl("Indie", genre, fixed = TRUE) == TRUE, 1, 0),
RnB = ifelse(grepl("R&B", genre, fixed = TRUE) == TRUE, 1, 0),
Alternative = ifelse(grepl("Alternative", genre, fixed = TRUE) == TRUE, 1, 0),
Folk = ifelse(grepl("Folk", genre, fixed = TRUE) == TRUE, 1, 0),
Soul = ifelse(grepl("Soul", genre, fixed = TRUE) == TRUE, 1, 0),
Country = ifelse(grepl("Country", genre, fixed = TRUE) == TRUE, 1, 0),
Jazz = ifelse(grepl("Jazz", genre, fixed = TRUE) == TRUE, 1, 0),
Electronic = ifelse(grepl("Electronic", genre, fixed = TRUE) == TRUE, 1, 0),
Reggaeton = ifelse(grepl("Reggaeton", genre, fixed = TRUE) == TRUE, 1, 0),
Reggae = ifelse(grepl("Reggae", genre, fixed = TRUE) == TRUE, 1, 0),
World = ifelse(grepl("World", genre, fixed = TRUE) == TRUE, 1, 0),
Blues = ifelse(grepl("Blues", genre, fixed = TRUE) == TRUE, 1, 0),
Ska = ifelse(grepl("Ska", genre, fixed = TRUE) == TRUE, 1, 0),)
spotify_data
track_id <chr> | genre <chr> | |
---|---|---|
000DfZJww8KiixTKuk9usJ | Reggae | |
000EWWBkYaREzsBplYjUag | Jazz | |
000xQL6tZNLJzIrtIgxqSl | Dance,Pop | |
001bQcMKt86oNbnWne4EAB | Reggaeton | |
001CyR8xqmmpVZFiTZJ5BC | Blues | |
001gDjxhKGDSx4sMMAgS9R | Rock | |
001ifh9Zkyc5DhK7AGQRtK | Folk,Indie | |
001KkOBeRiQ1J7IEJYHODW | World | |
001YQlnDSduXd5LgBd66gT | Ska | |
002opcRBgYV5jqoh72QcqA | Dance,Pop |
colnames(spotify_data)
## [1] "track_id" "genre" "artist_name" "track_name"
## [5] "popularity" "acousticness" "danceability" "duration_ms"
## [9] "energy" "instrumentalness" "key" "liveness"
## [13] "loudness" "mode" "speechiness" "tempo"
## [17] "time_signature" "valence" "Pop" "Rap"
## [21] "Rock" "Hip_Hop" "Dance" "Indie"
## [25] "RnB" "Alternative" "Folk" "Soul"
## [29] "Country" "Jazz" "Electronic" "Reggaeton"
## [33] "Reggae" "World" "Blues" "Ska"
nrow(spotify_data)
## [1] 128794
spotify_data_final <- spotify_data
colnames(spotify_data_final)
## [1] "track_id" "genre" "artist_name" "track_name"
## [5] "popularity" "acousticness" "danceability" "duration_ms"
## [9] "energy" "instrumentalness" "key" "liveness"
## [13] "loudness" "mode" "speechiness" "tempo"
## [17] "time_signature" "valence" "Pop" "Rap"
## [21] "Rock" "Hip_Hop" "Dance" "Indie"
## [25] "RnB" "Alternative" "Folk" "Soul"
## [29] "Country" "Jazz" "Electronic" "Reggaeton"
## [33] "Reggae" "World" "Blues" "Ska"
#Count tracks from each genre combination
genres_df <- group_by(spotify_data_final, genre) %>% summarize(tracks_count = length(genre))
genres_df
genre <chr> | tracks_count <int> | ||
---|---|---|---|
Alternative | 3829 | ||
Alternative,Blues | 98 | ||
Alternative,Blues,Country,Folk | 2 | ||
Alternative,Blues,Country,Folk,Indie,Rock | 4 | ||
Alternative,Blues,Dance | 4 | ||
Alternative,Blues,Dance,Folk,Indie,Rock | 4 | ||
Alternative,Blues,Dance,Folk,Rock | 2 | ||
Alternative,Blues,Dance,Indie,Rock | 31 | ||
Alternative,Blues,Dance,Rock | 11 | ||
Alternative,Blues,Folk,Indie,Rock | 2 |
Calculate mean, standard deviation, and coefficient of variation for each audio feature corresponding to each music genre combination (489 total)
genre_popularity_summary <- group_by(spotify_data_final, genre) %>%
summarize_at(vars(popularity),
list(pop_mean = mean,
pop_stdev = sd)) %>%
mutate(pop_cv = pop_stdev / pop_mean) %>%
arrange(desc(pop_mean))
genre_popularity_summary
genre <chr> | pop_mean <dbl> | pop_stdev <dbl> | pop_cv <dbl> | |
---|---|---|---|---|
Folk,Pop,R&B,Soul | 77.00000 | NA | NA | |
Pop,Reggae | 77.00000 | NA | NA | |
Dance,Electronic,Pop,Rap | 74.50000 | 0.7071068 | 0.009491366 | |
Alternative,Dance,Electronic,Indie,Pop,Rock | 74.00000 | 2.8284271 | 0.038221988 | |
Pop,Reggaeton | 73.27143 | 7.0153484 | 0.095744666 | |
Hip-Hop,Pop,Reggaeton | 72.85417 | 8.4198084 | 0.115570719 | |
Dance,Hip-Hop,Pop,Reggaeton | 72.61538 | 4.1137668 | 0.056651449 | |
Alternative,Pop,Rock,Ska | 72.50000 | 2.1213203 | 0.029259591 | |
Electronic,Rap | 72.50000 | 0.7071068 | 0.009753197 | |
Pop,Rock,Soul | 72.50000 | 5.0000000 | 0.068965517 |
genre_acousticness_summary <- group_by(spotify_data_final, genre) %>%
summarize_at(vars(acousticness),
list(acousticness_mean = mean,
acousticness_stdev = sd)) %>%
mutate(acousticness_cv = acousticness_stdev / acousticness_mean) %>%
arrange(desc(acousticness_mean))
genre_acousticness_summary
genre <chr> | acousticness_mean <dbl> | acousticness_stdev <dbl> | |
---|---|---|---|
Pop,World | 0.98850000 | 9.192388e-03 | |
Folk,Jazz,World | 0.94200000 | 2.262742e-02 | |
Blues,Folk,Jazz,Rock | 0.93166667 | 1.028915e-02 | |
Blues,Folk,Pop,Rock,Soul | 0.90800000 | 0.000000e+00 | |
Dance,Folk,Indie,Pop | 0.90800000 | 0.000000e+00 | |
R&B,Rock | 0.90400000 | NA | |
Folk,Jazz,Pop | 0.89925000 | 3.133023e-02 | |
Dance,Electronic,Folk,Indie,Pop | 0.87900000 | NA | |
Indie,World | 0.82550000 | 4.737615e-02 | |
Alternative,Folk,Pop | 0.81300000 | 6.391870e-02 |
genre_danceability_summary <- group_by(spotify_data_final, genre) %>%
summarize_at(vars(danceability),
list(danceability_mean = mean,
danceability_stdev = sd)) %>%
mutate(danceability_cv = danceability_stdev / danceability_mean) %>%
arrange(desc(danceability_mean))
genre_danceability_summary
genre <chr> | danceability_mean <dbl> | danceability_stdev <dbl> | |
---|---|---|---|
Indie,Pop,Rap,Reggae,Rock | 0.8700000 | NA | |
Electronic,Rap | 0.8670000 | 0.000000000 | |
Pop,Rap,Reggae | 0.8660000 | NA | |
Indie,Rap,Reggae | 0.8590000 | NA | |
Alternative,Hip-Hop,Indie | 0.8390000 | 0.000000000 | |
Dance,Pop,Rap,Reggae | 0.8353333 | 0.028867513 | |
Pop,Rap,Reggaeton | 0.8335000 | 0.026162951 | |
Alternative,Dance,Soul | 0.8292500 | 0.103057196 | |
Alternative,Hip-Hop,Reggaeton | 0.8290000 | 0.000000000 | |
Blues,Folk,Jazz,Soul | 0.8290000 | 0.000000000 |
genre_duration_ms_summary <- group_by(spotify_data_final, genre) %>%
summarize_at(vars(duration_ms),
list(duration_ms_mean = mean,
duration_ms_stdev = sd)) %>%
mutate(duration_ms_cv = duration_ms_stdev / duration_ms_mean) %>%
arrange(desc(duration_ms_mean))
genre_duration_ms_summary
genre <chr> | duration_ms_mean <dbl> | duration_ms_stdev <dbl> | |
---|---|---|---|
Alternative,Blues,Folk,Rock | 638427.0 | NA | |
Soul,World | 465318.8 | 285649.9230 | |
Folk,Reggae | 420731.5 | 12027.1792 | |
Jazz,Reggae,Soul | 420720.0 | NA | |
Folk,Jazz,World | 415583.5 | 150325.9519 | |
Indie,Jazz,World | 411513.5 | 122518.2707 | |
Dance,Electronic,Folk,Indie,Rock | 377387.0 | 0.0000 | |
Jazz,Rock | 371773.4 | 123517.3543 | |
Alternative,Dance,Electronic,Folk,Indie,Rock | 370058.5 | 49010.5612 | |
Jazz,Reggae | 343686.3 | 108186.7175 |
genre_energy_summary <- group_by(spotify_data_final, genre) %>%
summarize_at(vars(energy),
list(energy_mean = mean,
energy_stdev = sd)) %>%
mutate(energy_cv = energy_stdev / energy_mean) %>%
arrange(desc(energy_mean))
genre_energy_summary
genre <chr> | energy_mean <dbl> | energy_stdev <dbl> | energy_cv <dbl> |
---|---|---|---|
Alternative,Electronic,Indie,Pop,Rock | 0.9580000 | 0.000000000 | 0.000000000 |
Dance,Electronic,Jazz,Pop | 0.9490000 | 0.000000000 | 0.000000000 |
Alternative,Country,Indie,Rock | 0.9360000 | 0.000000000 | 0.000000000 |
Alternative,Rap,Reggae,Rock | 0.9280000 | 0.000000000 | 0.000000000 |
Pop,Rock,Ska | 0.9270000 | 0.014730920 | 0.015890960 |
Blues,Dance,Indie,Rock | 0.9242000 | 0.053129088 | 0.057486570 |
Dance,Indie,Rock,Ska | 0.9170000 | 0.000000000 | 0.000000000 |
Country,Pop,Rap,Rock | 0.9110000 | 0.013856406 | 0.015210106 |
Dance,Electronic,Folk,Indie,Rock | 0.9100000 | 0.000000000 | 0.000000000 |
Alternative,Rap | 0.9009252 | 0.110856245 | 0.123047117 |
genre_liveness_summary <- group_by(spotify_data_final, genre) %>%
summarize_at(vars(liveness),
list(liveness_mean = mean,
liveness_stdev = sd)) %>%
mutate(liveness_cv = liveness_stdev / liveness_mean) %>%
arrange(desc(liveness_mean))
genre_liveness_summary
genre <chr> | liveness_mean <dbl> | liveness_stdev <dbl> | liveness_cv <dbl> |
---|---|---|---|
Alternative,Hip-Hop,Reggaeton | 0.77600000 | 0.000000000 | 0.000000000 |
Dance,Electronic,Folk,Indie,Pop | 0.72200000 | NA | NA |
Alternative,Dance,Electronic,Folk,Indie | 0.56850000 | 0.234972977 | 0.413320980 |
Dance,Indie,Pop,Rap | 0.54000000 | 0.156272198 | 0.289392960 |
Reggae,Soul | 0.46660000 | 0.545037907 | 1.168105244 |
Country,Pop,Rap | 0.45900000 | NA | NA |
Alternative,Hip-Hop,Reggaeton,Rock | 0.40483333 | 0.423426578 | 1.045928146 |
Jazz,Reggae,Soul | 0.39300000 | NA | NA |
Alternative,Hip-Hop,Pop | 0.37900000 | 0.184093455 | 0.485734709 |
Folk,Indie,Pop,R&B | 0.37645000 | 0.442012449 | 1.174159779 |
genre_loudness_summary <- group_by(spotify_data_final, genre) %>%
summarize_at(vars(loudness),
list(loudness_mean = mean,
loudness_stdev = sd)) %>%
mutate(loudness_cv = loudness_stdev / loudness_mean) %>%
arrange(desc(loudness_mean))
genre_loudness_summary
genre <chr> | loudness_mean <dbl> | loudness_stdev <dbl> | loudness_cv <dbl> |
---|---|---|---|
Hip-Hop,Indie,R&B,Rap | -2.568000 | 0.85100000 | -0.33138629 |
Dance,Hip-Hop,Pop,Reggaeton | -3.139385 | 1.19665294 | -0.38117437 |
Alternative,Dance,Pop | -3.355500 | 0.69615537 | -0.20746696 |
Country,Pop,Rap,Rock | -3.470667 | 0.39548493 | -0.11395071 |
Pop,R&B,Rap,Rock | -3.472000 | NA | NA |
Folk,Indie,Ska | -3.530000 | 0.07495332 | -0.02123323 |
Dance,Reggaeton | -3.577000 | 1.33217917 | -0.37242918 |
Dance,Folk,Pop,R&B,Rock,Soul | -3.621000 | 0.00000000 | 0.00000000 |
Dance,Rap,Reggae | -3.903000 | NA | NA |
Dance,Pop,Rap,Reggae | -4.045333 | 0.90701727 | -0.22421323 |
genre_speechiness_summary <- group_by(spotify_data_final, genre) %>%
summarize_at(vars(speechiness),
list(speechiness_mean = mean,
speechiness_stdev = sd)) %>%
mutate(speechiness_cv = speechiness_stdev / speechiness_mean) %>%
arrange(desc(speechiness_mean))
genre_speechiness_summary
genre <chr> | speechiness_mean <dbl> | speechiness_stdev <dbl> | |
---|---|---|---|
Alternative,Hip-Hop,Indie,Pop,R&B,Rap | 0.55700000 | 0.0080829038 | |
Alternative,Hip-Hop,Indie,R&B,Rap | 0.36088889 | 0.1104441904 | |
Pop,Rap,Reggae | 0.36000000 | NA | |
Country,Hip-Hop,Pop,Rap | 0.31750000 | 0.1137380030 | |
Hip-Hop,Indie,Pop,Rap,Soul | 0.28500000 | NA | |
Country,Pop,Rap | 0.28300000 | NA | |
Country,Hip-Hop | 0.28078333 | 0.2306888330 | |
Hip-Hop,Indie,R&B | 0.28000000 | 0.0367559519 | |
Alternative,Hip-Hop,Jazz,Rap | 0.27694348 | 0.0832439031 | |
Alternative,Folk,R&B | 0.27390000 | 0.2772435993 |
genre_tempo_summary <- group_by(spotify_data_final, genre) %>%
summarize_at(vars(tempo),
list(tempo_mean = mean,
tempo_stdev = sd)) %>%
mutate(tempo_cv = tempo_stdev / tempo_mean) %>%
arrange(desc(tempo_mean))
genre_tempo_summary
genre <chr> | tempo_mean <dbl> | tempo_stdev <dbl> | tempo_cv <dbl> |
---|---|---|---|
Jazz,Pop | 202.08200 | NA | NA |
Alternative,Reggaeton | 199.95200 | 0.00000000 | 0.000000000 |
Electronic,Folk,World | 180.09000 | NA | NA |
Alternative,Dance,Electronic,Folk,Indie,Rock,World | 180.07400 | 0.00000000 | 0.000000000 |
Rap,Reggae | 172.90250 | 29.55352792 | 0.170925972 |
Dance,World | 172.61700 | 12.82237213 | 0.074282209 |
Dance,Folk,R&B,Soul | 169.47000 | 0.00000000 | 0.000000000 |
Alternative,Blues,Folk,Indie,Rock | 166.48800 | 0.00000000 | 0.000000000 |
Alternative,Pop,Reggae,Rock | 166.16300 | 0.00000000 | 0.000000000 |
Blues,Dance | 164.44250 | 19.17553449 | 0.116609359 |
genre_valence_summary <- group_by(spotify_data_final, genre) %>%
summarize_at(vars(valence),
list(valence_mean = mean,
valence_stdev = sd)) %>%
mutate(valence_cv = valence_stdev / valence_mean) %>%
arrange(desc(valence_mean))
genre_valence_summary
genre <chr> | valence_mean <dbl> | valence_stdev <dbl> | valence_cv <dbl> |
---|---|---|---|
Blues,Pop | 0.9730000 | NA | NA |
Dance,Folk,Pop,R&B,Rock,Soul | 0.9650000 | 0.0000000000 | 0.000000000 |
Dance,Folk,Pop | 0.9580000 | NA | NA |
Blues,Folk,Pop,Rock | 0.9570000 | 0.0000000000 | 0.000000000 |
Blues,Pop,Soul | 0.9390000 | 0.0334863156 | 0.035661678 |
Blues,Pop,Rock,Soul | 0.9380000 | 0.0000000000 | 0.000000000 |
Pop,Reggae | 0.9310000 | NA | NA |
Dance,Electronic,Folk,Indie,Rock | 0.9280000 | 0.0000000000 | 0.000000000 |
Alternative,Dance,Electronic,Indie,Pop,Rock | 0.9180000 | 0.0000000000 | 0.000000000 |
Alternative,Hip-Hop,Reggaeton | 0.8830000 | 0.0000000000 | 0.000000000 |
Merge audio features of genre into one dataframe
genres_data_list <- list(genres_df,
genre_popularity_summary,genre_acousticness_summary,
genre_danceability_summary,genre_duration_ms_summary,
genre_energy_summary,genre_liveness_summary,
genre_loudness_summary,genre_speechiness_summary,
genre_tempo_summary,genre_valence_summary)
#Merging multiple dataframes
my_merge <- function(df1, df2){
merge(df1, df2, by = 'genre')
}
genres_df <- Reduce(my_merge, genres_data_list)
genres_df
genre <chr> | tracks_count <int> | pop_mean <dbl> | pop_stdev <dbl> | |
---|---|---|---|---|
Alternative | 3829 | 47.07104 | 7.2091946 | |
Alternative,Blues | 98 | 48.81633 | 6.8252819 | |
Alternative,Blues,Country,Folk | 2 | 49.50000 | 2.1213203 | |
Alternative,Blues,Country,Folk,Indie,Rock | 4 | 55.00000 | 2.5819889 | |
Alternative,Blues,Dance | 4 | 46.50000 | 6.0277138 | |
Alternative,Blues,Dance,Folk,Indie,Rock | 4 | 59.00000 | 2.4494897 | |
Alternative,Blues,Dance,Folk,Rock | 2 | 53.00000 | 2.8284271 | |
Alternative,Blues,Dance,Indie,Rock | 31 | 57.06452 | 5.9717975 | |
Alternative,Blues,Dance,Rock | 11 | 53.54545 | 4.1319157 | |
Alternative,Blues,Folk,Indie,Rock | 2 | 54.50000 | 2.1213203 |
colnames(genres_df)
## [1] "genre" "tracks_count" "pop_mean"
## [4] "pop_stdev" "pop_cv" "acousticness_mean"
## [7] "acousticness_stdev" "acousticness_cv" "danceability_mean"
## [10] "danceability_stdev" "danceability_cv" "duration_ms_mean"
## [13] "duration_ms_stdev" "duration_ms_cv" "energy_mean"
## [16] "energy_stdev" "energy_cv" "liveness_mean"
## [19] "liveness_stdev" "liveness_cv" "loudness_mean"
## [22] "loudness_stdev" "loudness_cv" "speechiness_mean"
## [25] "speechiness_stdev" "speechiness_cv" "tempo_mean"
## [28] "tempo_stdev" "tempo_cv" "valence_mean"
## [31] "valence_stdev" "valence_cv"
#Sort order was lost on merge, resorting
genres_df <- genres_df[order(-genres_df$pop_mean,
genres_df$tracks_count),]
#Remove row index column
row.names(genres_df) <- NULL
genres_df
genre <chr> | tracks_count <int> | pop_mean <dbl> | pop_stdev <dbl> | |
---|---|---|---|---|
Folk,Pop,R&B,Soul | 1 | 77.00000 | NA | |
Pop,Reggae | 1 | 77.00000 | NA | |
Dance,Electronic,Pop,Rap | 2 | 74.50000 | 0.7071068 | |
Alternative,Dance,Electronic,Indie,Pop,Rock | 2 | 74.00000 | 2.8284271 | |
Pop,Reggaeton | 70 | 73.27143 | 7.0153484 | |
Hip-Hop,Pop,Reggaeton | 48 | 72.85417 | 8.4198084 | |
Dance,Hip-Hop,Pop,Reggaeton | 13 | 72.61538 | 4.1137668 | |
Alternative,Pop,Rock,Ska | 2 | 72.50000 | 2.1213203 | |
Electronic,Rap | 2 | 72.50000 | 0.7071068 | |
Pop,Rock,Soul | 4 | 72.50000 | 5.0000000 |
Detect how many music genre combinations are statistically significant (minimun of 100 tracks)
genres_df[genres_df$tracks_count >= 100,]
genre <chr> | tracks_count <int> | pop_mean <dbl> | pop_stdev <dbl> | pop_cv <dbl> | ||
---|---|---|---|---|---|---|
30 | Dance,Pop,Rock | 120 | 68.64167 | 6.431012 | 0.09368962 | |
41 | Pop | 1340 | 67.38955 | 7.886738 | 0.11703206 | |
42 | Dance,Pop,R&B | 360 | 67.37500 | 8.201905 | 0.12173513 | |
45 | Hip-Hop,Pop,Rap | 1590 | 67.31069 | 6.515631 | 0.09679934 | |
47 | Pop,Rap | 359 | 67.22006 | 8.601938 | 0.12796684 | |
50 | Folk,Pop,Rock | 107 | 67.08411 | 5.336103 | 0.07954346 | |
55 | Pop,Rock | 486 | 66.78395 | 7.032812 | 0.10530692 | |
57 | Hip-Hop,Pop,R&B,Rap | 121 | 66.53719 | 5.977794 | 0.08984140 | |
60 | Dance,Pop | 1859 | 66.47283 | 11.492577 | 0.17289133 | |
72 | Dance,Indie,Pop | 211 | 65.91943 | 7.696514 | 0.11675638 |
Irrelevant single genres removed: Movie, A Capella, Anime, Children's Music, Soundtrack,
Comedy, Opera, and Classical.
Total count of single genre tracks after filtering irrelevant genres: 121,411.
Total count of combined genres tracks after filtering irrelevant genres: 73,489
Most combined genres tend to outperform tracks associated with only a single genre. In other words,
tracks associated with more than one music genre tend to be more popular.
The chart below uses the same dataset as previous graph. A limited amount of single genres are displayed to preserve chart interpretability.
Let's examine how popular some audio features how and which single genres tend to be associated more with a particular audio feature (i.e. energy, danceability, duration, etc..)
Spotify uses the word “valence” to measure whether a song is likely to make someone feel happy (higher valence) or sad (lower valence).
Songs with elements of Dance, Pop, and Rock genres are the most likely to be profitable.
High correlation between danceability and popularity except
with electronic music.
Beats-Per-Minute (BPM) range of 120-125 is recommended. This range is easy to dance to.
Song duration of ~3.5 minutes is recommended for most genres but for rap music ~4.5 minutes is advised.
Wether a song makes you feel happy or sad doesn't play a significant role except for reggaeton.
Reggaeton songs that are too happy are not as popular.