【错误解决】Pandas DataFrame.to_csv raising IOError: No such file or directory?


报错的意思是说,没有对应的路径的文件夹。
虽然能够生成文件,但是必须要有生成的文件夹。

常用的方法是先判断是否文件夹存在,如果不存在,则先创建对应的文件夹。

import os

outname = 'name.csv'

outdir = './dir'
if not os.path.exists(outdir):
    os.mkdir(outdir)

fullname = os.path.join(outdir, outname)    

df.to_csv(fullname)

参考链接: https://stackoverflow.com/questions/47143836/pandas-dataframe-to-csv-raising-ioerror-no-such-file-or-directory


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM