Skip to content

Instantly share code, notes, and snippets.

Created October 12, 2021 08:58
What would you like to do?
import nltk
import re'stopwords')
stemmer = nltk.SnowballStemmer("english")
from nltk.corpus import stopwords
import string
def clean(text):
text = str(text).lower()
text = re.sub('\[.*?\]', '', text)
text = re.sub('https?://\S+|www\.\S+', '', text)
text = re.sub('<.*?>+', '', text)
text = re.sub('[%s]' % re.escape(string.punctuation), '', text)
text = re.sub('\n', '', text)
text = re.sub('\w*\d\w*', '', text)
text = [word for word in text.split(' ') if word not in stopword]
text=" ".join(text)
text = [stemmer.stem(word) for word in text.split(' ')]
text=" ".join(text)
return text
data["text"] = data["text"].apply(clean)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment