报错的意思是说,没有对应的路径的文件夹。 虽然能够生成文件,但是必须要有生成的文件夹。
常用的方法是先判断是否文件夹存在,如果不存在,则先创建对应的文件夹。
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