Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3450,6 +3450,20 @@ def to_csv(
... archive_name='out.csv') # doctest: +SKIP
>>> df.to_csv('out.zip', index=False,
... compression=compression_opts) # doctest: +SKIP

To write a csv file to a new folder or nested folder you will first
need to create it using either `Pathlib
<https://docs.python.org/3/library/pathlib.html#pathlib.Path.mkdir>`
or `os <https://docs.python.org/2/library/os.html#os.makedirs>`:

>>> from pathlib import Path
>>> filepath = Path('folder/subfolder/out.csv')
>>> filepath.parent.mkdir(parents=True, exist_ok=True)
>>> df.to_csv(filepath)

>>> import os
>>> os.makedirs('folder/subfolder', exist_ok=True)
>>> df.to_csv('folder/subfolder/out.csv')
"""
df = self if isinstance(self, ABCDataFrame) else self.to_frame()

Expand Down