liujuanjuan1984 / ucanuupnobb

you can you up, no bb. 自学 python 编程过程中的挑战、笔记及我的践友们。
17 stars 9 forks source link

【笔记】vscode中pd.ExcelWriter的用法报错,而在jupyter lab中正常 #20

Open liujuanjuan1984 opened 4 years ago

liujuanjuan1984 commented 4 years ago

今天是周一,用 python 脚本跑 xue.cn 数据统计分析的脚本,并输出结果到 excel 时,遇到一个报错:

image

代码中有以下报错: image

Abstract class 'ExcelWriter' with abstract methods instantiatedpylint(abstract-class-instantiated)

这个报警,自从我用 ExcelWriter方法时,一直就有,之前未产生异常。不过这次却直接导致代码没能运行通过。

而在 jupyter lab中,该代码就能直接运行通过,并正确输出结果。

什么原因,尚需探究。先记录下。

liujuanjuan1984 commented 4 years ago

修改1: image

为什么这么改: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.ExcelWriter.html 官网示例

结果: 报错 NameError: name 'ExcelWriter' is not defined

修改2:

with pd.ExcelWriter(comms_file, engine='xlsxwriter') as writer:

移除 engine 相关设定。

image

结果: 依然报错 FileNotFoundError: [Errno 2] No such file or directory: './output/xuecn_comments_statistics_2019-09-17 10:42.xlsx'

修改3: 可能真的是文件夹的问题了。。

检查了下,导入时未添加当前绝对路径到sys参数中

把路径申明从相对路径改成绝对路径,即可。

囧rz

output_path = 'C:/Users/75801/python_side_projects/xuecn_data/output/'

output_path = './output/'