Hip hop over time
Billboard has a “R and B / Hip Hop” list, which is a little absurd because the
genres aren’t quite the same. Let’s track the changes over the years.
And let’s get this out of the way now: every time you make a vectorizer,
you’ll want to ask yourself a few questions.
- What kind of vectorizer do you need? CountVectorizer? TfIdf?
- If TdIfd, do you use use_idf=True or use_idf=False?
- Does your vectorizer require a certain vocabulary?
- Do you care about multiple words (“he said” vs. “she said”)? If so, do you
need to do something special so it pays attention to that?
- Should you lemmatize/stem when you’re processing?
Reading in the files
Getting a list of every file we’ll want to read in
['hip-hop/1965/a-change-is-gonna-come-sam-cooke',
'hip-hop/1965/a-lovers-concerto-the-toys',
'hip-hop/1965/a-woman-can-change-a-man-joe-tex',
'hip-hop/1965/a-womans-love-carla-thomas',
'hip-hop/1965/aint-that-peculiar-marvin-gaye']
Reading in the files using a list comprehension
Use the filenames and the contents to build a dataframe
|
filename |
lyrics |
0 |
hip-hop/1965/a-change-is-gonna-come-sam-cooke |
[Verse 1]\nI was born by the river\nIn a littl... |
1 |
hip-hop/1965/a-lovers-concerto-the-toys |
How gentle is the rain\nThat falls softly on t... |
2 |
hip-hop/1965/a-woman-can-change-a-man-joe-tex |
A man can say what he won't do\nBut if she rea... |
3 |
hip-hop/1965/a-womans-love-carla-thomas |
When I ask you where you've been\nDon't get an... |
4 |
hip-hop/1965/aint-that-peculiar-marvin-gaye |
[Verse 1]\nHoney you do me wrong but still I'm... |
Extract the year into a different column
|
filename |
lyrics |
year |
0 |
hip-hop/1965/a-change-is-gonna-come-sam-cooke |
[Verse 1]\nI was born by the river\nIn a littl... |
1965 |
1 |
hip-hop/1965/a-lovers-concerto-the-toys |
How gentle is the rain\nThat falls softly on t... |
1965 |
Use the year to create a datetime column
Even though it’s a lie, because the billboard charts are weekly. I just didn’t
save that information!
|
filename |
lyrics |
year |
datetime |
0 |
hip-hop/1965/a-change-is-gonna-come-sam-cooke |
[Verse 1]\nI was born by the river\nIn a littl... |
1965 |
1965-01-01 |
1 |
hip-hop/1965/a-lovers-concerto-the-toys |
How gentle is the rain\nThat falls softly on t... |
1965 |
1965-01-01 |
Extract the artist and song name into another column
|
filename |
lyrics |
year |
datetime |
title-artist |
0 |
hip-hop/1965/a-change-is-gonna-come-sam-cooke |
[Verse 1]\nI was born by the river\nIn a littl... |
1965 |
1965-01-01 |
a-change-is-gonna-come-sam-cooke |
1 |
hip-hop/1965/a-lovers-concerto-the-toys |
How gentle is the rain\nThat falls softly on t... |
1965 |
1965-01-01 |
a-lovers-concerto-the-toys |
Cleaning up a little more
Let’s get rid of things like "[Verse 1]"
while we’re at it.
|
filename |
lyrics |
year |
datetime |
title-artist |
0 |
hip-hop/1965/a-change-is-gonna-come-sam-cooke |
I was born by the river\nIn a little tent\nAnd... |
1965 |
1965-01-01 |
a-change-is-gonna-come-sam-cooke |
1 |
hip-hop/1965/a-lovers-concerto-the-toys |
How gentle is the rain\nThat falls softly on t... |
1965 |
1965-01-01 |
a-lovers-concerto-the-toys |
OKAY! We did it. We’re done. it’s clean. Let’s get down to business.
Text analysis
What do you want to do?
|
gin |
patron |
0 |
0 |
0 |
1 |
0 |
0 |
2 |
0 |
0 |
3 |
0 |
0 |
4 |
0 |
0 |
|
filename |
lyrics |
year |
datetime |
title-artist |
0 |
hip-hop/1965/a-change-is-gonna-come-sam-cooke |
I was born by the river\nIn a little tent\nAnd... |
1965 |
1965-01-01 |
a-change-is-gonna-come-sam-cooke |
1 |
hip-hop/1965/a-lovers-concerto-the-toys |
How gentle is the rain\nThat falls softly on t... |
1965 |
1965-01-01 |
a-lovers-concerto-the-toys |
2 |
hip-hop/1965/a-woman-can-change-a-man-joe-tex |
A man can say what he won't do\nBut if she rea... |
1965 |
1965-01-01 |
a-woman-can-change-a-man-joe-tex |
|
filename |
lyrics |
year |
datetime |
title-artist |
gin |
patron |
0 |
hip-hop/1965/a-change-is-gonna-come-sam-cooke |
I was born by the river\nIn a little tent\nAnd... |
1965 |
1965-01-01 |
a-change-is-gonna-come-sam-cooke |
0 |
0 |
1 |
hip-hop/1965/a-lovers-concerto-the-toys |
How gentle is the rain\nThat falls softly on t... |
1965 |
1965-01-01 |
a-lovers-concerto-the-toys |
0 |
0 |
2 |
hip-hop/1965/a-woman-can-change-a-man-joe-tex |
A man can say what he won't do\nBut if she rea... |
1965 |
1965-01-01 |
a-woman-can-change-a-man-joe-tex |
0 |
0 |
3 |
hip-hop/1965/a-womans-love-carla-thomas |
When I ask you where you've been\nDon't get an... |
1965 |
1965-01-01 |
a-womans-love-carla-thomas |
0 |
0 |
4 |
hip-hop/1965/aint-that-peculiar-marvin-gaye |
Honey you do me wrong but still I'm crazy abou... |
1965 |
1965-01-01 |
aint-that-peculiar-marvin-gaye |
0 |
0 |
<matplotlib.axes._subplots.AxesSubplot at 0x185a3cac8>
<matplotlib.axes._subplots.AxesSubplot at 0x18619cef0>
ARE RAPPERS ANGRY?????
Read in the emotional lexicon
emotion |
word |
anger |
anticipation |
disgust |
fear |
joy |
negative |
positive |
sadness |
surprise |
trust |
0 |
aback |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
abacus |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
2 |
abandon |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
Pull out the words you want
We want angry and positive
Get the percentage of words that we have emotional ratings for
|
aback |
abacus |
abandon |
abandoned |
abandonment |
abate |
abatement |
abba |
abbot |
abbreviate |
... |
zephyr |
zeppelin |
zest |
zip |
zodiac |
zone |
zoo |
zoological |
zoology |
zoom |
0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
... |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
1 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
... |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
2 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
... |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
3 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
... |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
4 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
... |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
0.0 |
5 rows × 14182 columns
Add up the percent that are angry and the percent that are positive
|
filename |
lyrics |
year |
datetime |
title-artist |
gin |
patron |
anger |
positivity |
0 |
hip-hop/1965/a-change-is-gonna-come-sam-cooke |
I was born by the river\nIn a little tent\nAnd... |
1965 |
1965-01-01 |
a-change-is-gonna-come-sam-cooke |
0 |
0 |
0.000000 |
0.142857 |
1 |
hip-hop/1965/a-lovers-concerto-the-toys |
How gentle is the rain\nThat falls softly on t... |
1965 |
1965-01-01 |
a-lovers-concerto-the-toys |
0 |
0 |
0.022727 |
0.409091 |
2 |
hip-hop/1965/a-woman-can-change-a-man-joe-tex |
A man can say what he won't do\nBut if she rea... |
1965 |
1965-01-01 |
a-woman-can-change-a-man-joe-tex |
0 |
0 |
0.000000 |
0.090909 |
<matplotlib.axes._subplots.AxesSubplot at 0x110e73978>
<matplotlib.axes._subplots.AxesSubplot at 0x1866bb198>