文本分类模型的预处理

怎么用代码在juypter上去除长文本的特殊字符并分词,然后导入自己的停用词表,去停用词,每一步都运行后都能看到datafram的表格,最后保存。

1.使用字符串处理方法去除特殊字符,可用filter函数,也可用re正则 :
2.分词用jieba.cut(),去除停用词使用列表解析式:wd=[w for w in words if w not in stopword]

import re
import jieba
s = "Hey! What's up bro?"
stopword=['up','bro']
a=''.join(filter(lambda x:x.isalnum() or x==" ", s)) 
b = re.sub(r"[^a-zA-Z0-9\s]","",s)
c=[w for w in jieba.cut(a) if w not in stopword and w!=' ']
print(a,b)
print(c)

3.使用pandas的apply等函数结合1,2处理方法形成新的数据框。