2 Upvotes

Remove Stop Words from Text in DataFrame Column

Here we have a dataframe column that contains tweet text data. We use Pandas apply with the lambda function and list comprehension to remove stop words declared in NLTK.

import nltk
nltk.download('stopwords')
from nltk.corpus import stopwords

stop_words = stopwords.words('english')
df['tweet'] = df['tweet'].apply(lambda x: ' '.join([word for word in x.split() if word not in (stop_words)]))

By detro - Last Updated Jan. 17, 2021, 8:37 p.m.

Did you find this snippet useful?

Sign up to bookmark this in your snippet library

COMMENTS
RELATED SNIPPETS
Top Contributors
75