Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to explore the music style of your favorite singer

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to use Python to explore the music style of your favorite singer, this article introduces the corresponding analysis and answer in detail, hoping to help more friends who want to solve this problem to find a more simple and feasible way.

In May 2019, Tones and I released her second single "Dance Monkey", which has been popular all over the world. You must have swayed to the rhythm of this song!

The first time I knew this song was in a class, and my friend kept singing it. At first, I felt as if he had repeated the same lyrics over and over again: "dancefor me, dancefor me, dancefor me". After listening to the original song, I noticed that it did have some repetitive lyrics. The author then listened to her other hit song "Never Seen The Rain" and found a similar pattern.

The author decided to explore the artist's own style in choosing the lyrics on the basis of this small project.

I'll use basic python skills to analyze Tones and I's two hits, "Dance Monkey" and "Never Seen The Rain", to see if there are any similarities between them, and how she creates her own musical style through repetition of lyrics, such as using phonetic words such as "oh" and "ah".

1. Collect and clean up data

The author obtained the lyrics of the two songs from Metro Lyrics and edited them to ensure that there were no commas or extra spaces between the lyrics, and changed words such as "You've" to "You have" to maintain consistency. After that, the author uploads it to JupyterNotebook as a string and assigns it a variable (dm&nstr).

# Dance Monkey Lyrics dm = "They say oh my god I see the way you shine Take your hand my...makeyou do it all again All again" dmdm = dm.lower () # Never Seen The Rain Lyrics nstr = "All your life no You could...never felt the rain rain rain" nstrnstr = nstr.lower ()

The dm.lower () function changes the words to make sure they are all lowercase. If you don't, the program will think that "You" is different from "you" and that they are different words. After printing, the result will be as follows:

Because one of the goals is to find out how many words there are in the lyrics, this cannot be done when all the words are in one string. To separate them, the author uses the following code:

Split_dm = dm.split ('') print (split_dm)

I did the same with Never Seen The Rain's lyrics.

two。 Classified data

The next step is to calculate the total number of words and unique words. In order to calculate the total number of words, the author uses the LEN () function on the initial variable:

Len (split_dm)

A total of 453 words. Then, in order to calculate the number of individual words used to write the song, the author uses the SET () function on the split_dm variable.

Unique_dm = set (split_dm) print (unique_dm)

This function ensures that words that are used at least once are listed, so the result is as follows:

To calculate the number of words in the new list, the author uses the LEN () function:

Len (unique_dm)

There are a total of 72 unique words, meaning that only these words are used in the creation of this song.

3. The most commonly used words

Among the words to be used, the author wants to identify the first 10 words (the most repeated words) and the words that are used only once. The code used below shows each word and its usage count:

Word_dm = {} for word in unique_dm: word_ dm [word] = 0for word insplit_dm: word_ dm [word] = word_ dm [word] + 1 print (word_dm)

To make it easier to read, the author uses the following code to tie words and values together:

Dm_count = sorted (word_dm.items (), key = lambda TRV [1], reverse = True) print (dm_count)

Then, use this code to retrieve the top 10 most commonly used words:

Dm_top_10 = dm_count [0:10] dm_top_10

The merged data is as follows:

The author can say for sure that the unique style of "Tones and I" (absolutely heard in all her songs) is the use of original words such as "oh" and "ay" in her songs, which rank in the top 10 in both of her songs.

4. A word that has only been used once

Image source: unsplash

Using code similar to the above, the author also found words that were used only once:

Dm_least_used = dm_count [49:72] len (dm_least_used)

There are only 23 words that are used only once. Another song uses the same function.

5. Number of repetitive words

The next goal is to find out the number of words that are repeated more than once:

Len (unique_dm)-len (dm_least_used)

There are 49 words repeated in this song. To find the number of repeats, the author uses the following code:

Len (split_dm)-len (dm_least_used)

These 49 words have been repeated 430 times! Similarly, the same code is executed in another song.

6. Visualization

The author merges the data from the two songs into the excel table and reads them on the notebook.

Table = pd.read_csv ('song_values.csv')

The most efficient way to compare data is to use bar charts:

X = table.Name Y1 = table.words_in_song Y2 = table.words_in_lyrics Y3 = table.Words_used_once Y4 = table.Words_used_more_than_once Y5 = table.Number_of_times_words_repeatedfig = go.Figure (data= [go.Bar (name='Total number of words insong', xx=x, y=y1), go.Bar (name='Total Number of RepeatedWords', xx=x, y=y5), go.Bar (name='Number of words used inLyric', xx=x, y=y2)) Go.Bar (name='Words used once', xx=x,y=y3), go.Bar (name='Words used more thanonce', xx=x,y= y4)]) # Change the barmode fig.update_layout (barmode='group', title = "Comparison Between The TwoSongs") fig.show ()

Looking at the chart, we can draw the following conclusions:

The number of words used once in the lyrics of the two songs is relatively the same as the number of words repeated more than once, although there are slightly more words in "Dance Monkey".

Nevertheless, the number of repetitions of words in "Dance Monkey" is much higher than that in "Never Seen The Rain".

Of the words that make up the lyrics, less than half have been used only once.

7. The last thought

In further processing the data, the author found a very interesting phenomenon, that is, how frequently the two words in the title are used: "Dance" is used 19 times, while "Monkey" is used only once in the whole song.

Surprisingly, the number of single words used to create lyrics is very small (about 15% of which is 20%), of which about 85% of the single words are reused to make up the song.

Image source: unsplash

After finishing this project, I was almost brainwashed by the song Dance Monkey. Try to explore your favorite singer in the same way, and you may be able to dig up his unknown writing habits.

This is the answer to the question on how to use Python to explore the music style of your favorite singers. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report