【发布时间】:2019-09-13 07:48:58
【问题描述】:
I am new in python and want to apply p reprocessing steps
so here is decoding error
import nltk
from nltk.tokenize import word_tokenize,sent_tokenize
from nltk.corpus import stopwords
from nltk.tag import pos_tag
from nltk.stem import PorterStemmer
`ps=PorterStemmer()
print ("\n Reading file with out stopwords.")
text_file=open('preprocessing.txt',encoding='utf-8').read()
stop_words= set(stopwords.words("english"))
words=word_tokenize(text_file)
filtered_sentence = [w for w in words if not w in stop_words]
print(filtered_sentence)
print ("\n Removed stopword.")
print(stop_words)
print ("\n Stemming.")
for w in text_file:
print (ps.stem(w))
print(w)
print(sent_tokenize(text_file))
print ("\n tokenization.")
print(word_tokenize(text_file))
print ("\n part of speech tagging.")
print (pos_tag(words)) `
" 我想以特定格式显示结果,但输出是 ",第 322 行,在解码中 (结果,消耗)= self._buffer_decode(数据,self.errors,最终) UnicodeDecodeError:“utf-8”编解码器无法解码位置 257 中的字节 0x92: 无效的起始字节”
【问题讨论】:
-
您确定您的文件是使用 UTF-8 编码的吗?
-
没有怎么编码?
-
如果你不确定你的文件有什么编码,你可以试试
chardet来弄明白。
标签: python-3.x