鱼C论坛

 找回密码
 立即注册
查看: 2137|回复: 1

想麻烦大佬看看为什么错呢,应该怎么改?

[复制链接]
发表于 2021-2-26 15:10:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #数据读取
  2. import pandas as pd

  3. df=pd.read_csv('D:\\本人\\必须冲!\\学nlp\\安徽.csv')   #此处路径需要修改

  4. with open('实验.txt','w+',encoding='utf-8') as f:
  5.     for i in range(len(df)):
  6.         f.write(str(df['内容'][i])+'\n')

  7. import codecs
  8. import re
  9. import numpy as np
  10. import pymysql
  11. from snownlp import SnowNLP
  12. import matplotlib.pyplot as plt
  13. from snownlp import sentiment
  14. from snownlp.sentiment import Sentiment


  15. comment = []
  16. with open('安徽.txt', mode='r', encoding='utf-8') as f:
  17.     rows = f.readlines()
  18.     for row in rows:
  19.         if row not in comment:
  20.             comment.append(row.strip('\n'))

  21. key=[]
  22. values=[]
  23. re=[]
  24. def snowanalysis(self):
  25.     sentimentslist = []
  26.     for li in self:
  27.         #text = re.sub(r'(?:回复)?(?://)?@[\w\u2E80-\u9FFF]+:?|\[\w+\]', ',',li)
  28.         s = SnowNLP(li)
  29.         
  30.         key.append(li)
  31.         values.append(s.sentiments)
  32.         sentimentslist.append(s.sentiments)
  33.     plt.figure(figsize=(12,8))
  34.     plt.hist(sentimentslist, bins=np.arange(0, 1, 0.01))
  35.     plt.show()
  36.    
  37. snowanalysis(comment)

  38. res=pd.DataFrame({'评论':key,'评分':values})

  39. #保存文件为excel格式
  40. res.to_excel('D:\\本人\\必须冲!\\学nlp\\安徽(实验).xlsx')  #此处路径需要修改�
复制代码


C:\Users\lyl\PycharmProjects\pythonProject1\venv\Scripts\python.exe "D:/本人/必须冲!/学nlp/微博评论评分 - 可用.py"
Traceback (most recent call last):
  File "D:/本人/必须冲!/学nlp/微博评论评分 - 可用.py", line 4, in <module>
    df=pd.read_csv('D:\\本人\\必须冲!\\学nlp\\安徽.csv')   #此处路径需要修改
  File "C:\Users\lyl\PycharmProjects\pythonProject1\venv\lib\site-packages\pandas\io\parsers.py", line 610, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "C:\Users\lyl\PycharmProjects\pythonProject1\venv\lib\site-packages\pandas\io\parsers.py", line 468, in _read
    return parser.read(nrows)
  File "C:\Users\lyl\PycharmProjects\pythonProject1\venv\lib\site-packages\pandas\io\parsers.py", line 1057, in read
    index, columns, col_dict = self._engine.read(nrows)
  File "C:\Users\lyl\PycharmProjects\pythonProject1\venv\lib\site-packages\pandas\io\parsers.py", line 2061, in read
    data = self._reader.read(nrows)
  File "pandas\_libs\parsers.pyx", line 756, in pandas._libs.parsers.TextReader.read
  File "pandas\_libs\parsers.pyx", line 771, in pandas._libs.parsers.TextReader._read_low_memory
  File "pandas\_libs\parsers.pyx", line 827, in pandas._libs.parsers.TextReader._read_rows
  File "pandas\_libs\parsers.pyx", line 814, in pandas._libs.parsers.TextReader._tokenize_rows
  File "pandas\_libs\parsers.pyx", line 1951, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 3, saw 2

安徽.rar

266.69 KB, 下载次数: 2

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-2-26 16:41:10 | 显示全部楼层
https://blog.csdn.net/alicelmx/article/details/83902760
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-27 10:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表