-
-
Save amankharwal/3e6fe854839314189062a5e53397958b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nltk | |
import re | |
nltk.download('stopwords') | |
stemmer = nltk.SnowballStemmer("english") | |
from nltk.corpus import stopwords | |
import string | |
stopword=set(stopwords.words('english')) | |
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