2016-05-18 109 views
2

我試圖來標記一些文件,但我有這個錯誤蟒蛇符號化的UnicodeDecodeError

UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 6: ordinal not in range(128)

import nltk 
import pandas as pd 

df = pd.DataFrame(pd.read_csv('status2.csv')) 
documents = df['status'] 

result = [nltk.word_tokenize(sent) for sent in documents] 

我認爲這是unicode的問題,所以我說

documents = unicode(documents, 'utf-8') 

另一個錯誤

TypeError: coercing to Unicode: need string or buffer, Series found

print documents 

1  Brandon Cachia ,All I know is that,you're so n... 
2  Melissa Zejtunija:HAM AND CHEESE BIEX INI??? *... 
3       .........Where is my mind????? 
4  Having a philosophical discussion with Trudy D... 

回答

1

unicode對字符串或字節進行操作,但documents是一個熊貓系列。

可能:

result = [nltk.word_tokenize(unicode(sent, 'utf-8')) for sent in documents]