currently to_csv
will create a file if it does not exist. However it will not create a folder (nor sub-folders).
In this case it will raise
IOError: [Errno 2] No such file or directory:
The user must wrap his code in order for it to create a folder.
I'm not sure why the function behaves like this.. It would be great if it will also create folders if needed.
Reference from stack overflow:
https://stackoverflow.com/questions/47143836/pandas-dataframe-to-csv-raising-ioerror-no-such-file-or-directory
this is out of scope for pandas itself as it can easily be accomplished by the user
In this case, pd.to_csv()
is also out of scope, since the user can "easily" open the file from Python and stream the dataframe content into it.
@JivanRoquet i agree with you, pandas has been known for being beginner friendly, and a simple SO search can guarantee that making directories for output files is a very common issue for python users, particularly analysts that know how to use pandas, but dont really now about filesystems.
On the other side, the last pandas community survey indicated that feature creep is an important issue for the community. @jreback maybe makes sense to add a comment with instructions to the docstring of the to_csv
function as a compromise?
Most helpful comment
In this case,
pd.to_csv()
is also out of scope, since the user can "easily" open the file from Python and stream the dataframe content into it.