To write piece of python code to remove stopwords (Useless words) from the text data using python.
Text data.
Stop word removed sentence.
Import nltk library.
Took sample text data.
Do tokenize the words in the text data.
Compare text data with stop words using loops.
Print the filtered sentence.
#import libraries
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
stopwords = list(stopwords.words(‘english’))
print(“Common stopwords are\n\n”,stopwords,”\n”)
text =’python is a scripting language it is as one of the general purpose language’
print(“Original text\n”,text)
filtered_sentence = []
word_tokens = word_tokenize(text)
print(“\n”)
print(“Tokinized sentence”)
for w in word_tokens:
if w not in stopwords:
filtered_sentence.append(w)
print(word_tokens)
print(“\n”)
print(“After removal of stopwords\n”,filtered_sentence)