Menu

Removing Stopwords

Removing Stopwords

Stopwords are commonly used words that usually do not add significant meaning to a sentence.

Examples include:

  • the
  • is
  • and
  • of
  • to
  • was
  • in

Removing stopwords reduces noise and improves model performance.

Code

stop_words = set(stopwords.words('english'))

Create Function

def remove_stopwords(text):
words = text.split()
filtered = [
word for word in words
if word not in stop_words
]
return " ".join(filtered)

Apply Function

df['clean_review'] = df['clean_review'].apply(remove_stopwords

Display Results

df[['review','clean_review']].head()