remove stopwords

Solutions on MaxInterview for remove stopwords by the best coders in the world

showing results for - "remove stopwords"
Hafsa
23 Mar 2017
1from nltk.corpus import stopwords
2from nltk.tokenize import word_tokenize
3 
4example_sent = """This is a sample sentence,
5                  showing off the stop words filtration."""
6 
7stop_words = set(stopwords.words('english'))
8 
9word_tokens = word_tokenize(example_sent)
10 
11filtered_sentence = [w for w in word_tokens if not w.lower() in stop_words]
Idriss
13 Feb 2016
1traindf['title'] = traindf['title'].apply(lambda x: ' '.join([word for word in x.lower().split() if word not in 
2                                                            stopwords.words('english') and string.punctuation]))