Pandas DataFrame.to_csv raising IOError: No such file or directory

to_csv does create the file if it doesn’t exist as you said, but it does not create directories that don’t exist. Ensure that the subdirectory you are trying to save your file within has been created first.

I often do something like this in my work:

import os


if not os.path.exists(outdir):

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


This can easily be wrapped up in a function if you need to do this frequently.

Leave a Comment