【錯誤解決】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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章