text processing

南笙酒味 提交于 2020-02-05 22:59:27

Import libraries

from nltk.corpus import stopwords
from textblob import TextBlob
from textblob import Word

Lower casing and removing punctuations

df[‘Text’] = df[‘Text’].apply(lambda x: " “.join(x.lower() for
x in x.split()))
df[‘Text’] = df[‘Text’].str.replace(’[^\w\s]’,”)
df.Text.head(5)

Removal of stop words

stop = stopwords.words(‘english’)
df[‘Text’] = df[‘Text’].apply(lambda x: " ".join(x for x in
x.split() if x not in stop))

Spelling correction

df[‘Text’] = df[‘Text’].apply(lambda x: str(TextBlob(x).
correct()))

Lemmatization

df[‘Text’] = df[‘Text’].apply(lambda x: " ".join([Word(word).
lemmatize() for word in x.split()]))

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!