我在python中使用NLTK包中的WordNetLemmatizer()函数来对电影评论数据集的整个句子进行lemmatize。你知道吗
这是我的密码:
from nltk.stem import LancasterStemmer, WordNetLemmatizer
lemmer = WordNetLemmatizer()
def preprocess(x):
#Lemmatization
x = ' '.join([lemmer.lemmatize(w) for w in x.rstrip().split()])
# Lower case
x = x.lower()
# Remove punctuation
x = re.sub(r'[^\w\s]', '', x)
# Remove stop words
x = ' '.join([w for w in x.split() if w not in stop_words])
## EDIT CODE HERE ##
return x
df['review_clean'] = df['review'].apply(preprocess)
df中的review是我想要处理的文本评论列
在df上使用preprocess函数后,新的列review\u clean包含清理过的文本数据,但仍然没有柠檬化的文本。我能看到很多词以-ed,-ing结尾。你知道吗
提前谢谢。你知道吗
你必须传递'v'(动词)来柠檬化:
示例:
相关问题 更多 >
编程相关推荐