賞金將在 2 天內到期。此問題的答案有資格獲得 50聲望賞金。 sariii希望引起對這個問題的更多關注。
我正在嘗試運行此腳本:在此處輸入鏈接描述
(唯一的區別是,TEST_SENTENCES 我需要讀取我的資料集(列文本)而不是這個。唯一的事情是我需要在傳遞之前對該列應用停用詞洗掉到代碼的其余部分。
df = pd.DataFrame({'text': ['the "superstar breakfast" is shrink wrapped muffins that can be bought at a convenience store.',
'The wireless internet was unreliable. ', 'i am still her . :). ',
'I appreciate your help ', 'I appreciate your help '], 'sentiment':[
'positive', 'negative', 'neutral', 'positive', 'neutral']})
但是當我以這種方式使用資料框時不會引發錯誤,但是當我使用包含完全相同資料的 csv 檔案時會引發錯誤。
但是當我添加這行代碼來洗掉stop_words
df['text_without_stopwords'] = df['text'].apply(lambda x: ' '.join([word.encode('latin1', 'ignore').decode('latin1') for word in x.split() if word not in (stop)]))
TEST_SENTENCES = df['text_without_stopwords']
它不斷引發此錯誤:
ValueError: All sentences should be Unicode-encoded!
此外,在標記化步驟中也會出現錯誤:
tokenized, _, _ = st.tokenize_sentences(TEST_SENTENCES)
我想知道這里發生了什么導致此錯誤,以及修復代碼的正確解決方案。
(我嘗試過不同的編碼,比如uff-8等,但沒有用)
uj5u.com熱心網友回復:
我還不知道原因,但是當我知道的時候
df['text_without_stopwords'] = df['text_without_stopwords'].astype('unicode')
有效。
仍然很想知道為什么只有當我這樣做時才會發生這種情況stop words removal
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/443965.html
標籤:熊猫 python-2.7 CSV 统一码 停用词
下一篇:執行緒阻塞主執行緒
