这是我的代码
CSV文件的URL:https://github.com/eugeneketeni/web-mining-final-project/blob/master/Test_file.csv
import pandas as pd
data = pd.read_csv("https://raw.githubusercontent.com/eugeneketeni/web-
mining-final-project/master/Test_file.csv")
import nltk
from nltk import word_tokenize, sent_tokenize
data['text'] = data.loc[:, 'text'].astype(str)
text = data.loc[:, "text"].astype(str)
tokenizer = [word_tokenize(text[i]) for i in range(len(text))]
print(tokenizer)
filtered_sentence = []
from nltk.corpus import stopwords
stopwords = set(stopwords.words('english'))
filtered_sentence = [w for w in tokenizer if not w in stopwords]
print(filtered_sentence)
我的tokenizer工作,但当我尝试删除默认的停用词时,我不断收到“unhashable type:'list'”错误 . 我不确定到底发生了什么 . 我将不胜感激任何帮助 . 谢谢 .
1 回答
TL; DR
长
有关更多详细说明,请参阅Why is my NLTK function slow when processing the DataFrame?:
标记数据框中的文本
删除停用词
其他相关的清洁过程
为了更好,twitter文本处理
然后用这个:
来自nltk.corpus导入的停用词