Course Content
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_stopword
that takes a listx
as 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 listx
using 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 DataFrametemp
to exclude the first row and select all columns;temp.style.background_gradient(...)
: Applies a background gradient style to a DataFrametemp
.
Task
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"
.
Task
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"
.
Mark tasks as Completed
Switch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?
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_stopword
that takes a listx
as 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 listx
using 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 DataFrametemp
to exclude the first row and select all columns;temp.style.background_gradient(...)
: Applies a background gradient style to a DataFrametemp
.
Task
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"
.
Mark tasks as Completed
Switch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 8
AVAILABLE TO ULTIMATE ONLY