Kursinnhold
Tweet Sentiment Analysis
Words Count
Now we would like to explore the most represented number in our DataFrame. For this reason we will create a collection where we will store the most frequent words and then, plot it.
Methods description
from collections import Counter; import nltk: Imports the Counter class from the collections module and the nltk library;from nltk.corpus import stopwords: Imports a list of common stopwords from NLTK;nltk.download("stopwords"): Downloads the stopwords dataset from NLTK;def remove_stopword(x): This defines a function namedremove_stopwordthat takes a listxas input and returns a new list with stopwords removed;return [y for y in x if y not in stopwords.words("english")]: This comprehension expression filters out stopwords from the input listxusing the list of English stopwords from NLTK;Counter: A class from the collections module used to count occurrences of elements in a list or iterable;stopwords.words("english"): A method from NLTK that returns a list of stopwords for the English language;temp.most_common(25): Returns the 25 most common elements (words) and their counts from the Counter objecttemp;temp.iloc[1:,:]: Indexes a DataFrametempto exclude the first row and select all columns;temp.style.background_gradient(...): Applies a background gradient style to a DataFrametemp.
Oppgave
Swipe to start coding
Create a collection to count word occurrences using the Counter module:
- Remove stopwords from our tweets texts.
- Create a collection.
- Create a DataFrame with the newly created list.
- Change the background color to
"Blues".
Løsning
Mark tasks as Completed
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 8
AVAILABLE TO ULTIMATE ONLY