在进行词频统计时,停用词出现报错:
stopwords = pandas.read_csv("D:\demo\stopwords.txt",encoding='utf-8',index_col=False,quoting=3,sep="\t")
报错:
Traceback (most recent call last):
File "D:\demo\程序\wbfx\4.6.2.py", line 63, in
fSegStat = segStat[~segStat.segment.isin(stopwords.stopword)]
File "D:\demo\venv\lib\site-packages\pandas\core\generic.py", line 5575, in getattr
return object.getattribute(self, name)
AttributeError: 'DataFrame' object has no attribute 'stopword'
Process finished with exit code 1
希望能够各位帮忙解决!
1.读取文件路径要改一下:
stopwords = pandas.read_csv("D:/demo/stopwords.txt",encoding='utf-8',index_col=False,quoting=3,sep="\t")
2.在stopwords.txt中要有列名stopword才可以。
例子:
import pandas
stopwords = pandas.read_csv("F:/2022/py01/t0407.txt",encoding='utf-8',index_col=False,sep=",")#stopwords.txt中有对应的列名
print(stopwords.词性)
'''
0 n
1 v
2 v
3 n
4 v
'''
不是读入这一行出了问题,报错是说在指定的dataframe中找不到stopword这一属性,贴一下你的完整代码,对着报错中给出的的行号索引一下问题
报错的意思是说'DataFrame'没有'stopword'这个属性,同时你给出的这一行代码并不是报错的位置,建议给出完整的代码与stopwords.txt文件
文件夹路径要么用正斜杠,要么在前面加上r
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!