JSxiiii 2022-04-07 14:48 采纳率: 100%
浏览 1089
已结题

python报错:AttributeError: 'DataFrame' object has no attribute 'stopword'

在进行词频统计时,停用词出现报错:

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

希望能够各位帮忙解决!

  • 写回答

5条回答 默认 最新

  • CSDN专家-HGJ 2022-04-07 15:27
    关注

    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
    '''
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(4条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月7日
  • 已采纳回答 4月7日
  • 创建了问题 4月7日

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格