xxxxxxxxxx
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
example_sent = "This is a sample sentence, showing off the stop words filtration."
stop_words = set(stopwords.words('english'))
word_tokens = word_tokenize(example_sent)
filtered_sentence = [w for w in word_tokens if not w in stop_words]
filtered_sentence = []
for w in word_tokens:
if w not in stop_words:
filtered_sentence.append(w)
print(word_tokens)
print(filtered_sentence)
xxxxxxxxxx
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
example_sent = """This is a sample sentence,
showing off the stop words filtration."""
stop_words = set(stopwords.words('english'))
word_tokens = word_tokenize(example_sent)
filtered_sentence = [w for w in word_tokens if not w.lower() in stop_words]
xxxxxxxxxx
traindf['title'] = traindf['title'].apply(lambda x: ' '.join([word for word in x.lower().split() if word not in
stopwords.words('english') and string.punctuation]))
xxxxxxxxxx
from nltk.tokenize import word_tokenize,sent_tokenize # import tokenize
from nltk.corpus import stopwords #import stopwords
sw=stopwords.words("english") # to get stopwords in english
text="hello i need to go For a walk but i don't know where to walk and when to walk to make my walk plesant."
final=[]
for word in word_tokenize(text): #itterate each word in text
if word not in sw:
final.append(word)
final