Skip to content

Commit a7c371f

Browse files
author
Joeperdefloep
committed
DOC: create folders in to_csv pandas-dev#24306
1 parent 3ce150d commit a7c371f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pandas/core/generic.py

+11
Original file line numberDiff line numberDiff line change
@@ -3450,6 +3450,17 @@ def to_csv(
34503450
... archive_name='out.csv') # doctest: +SKIP
34513451
>>> df.to_csv('out.zip', index=False,
34523452
... compression=compression_opts) # doctest: +SKIP
3453+
3454+
Create 'out.csv' in a new folder 'folder/subfolder/'
3455+
3456+
>>> import os
3457+
>>> os.mkdir('folder/subfolder', parents=True, exists_ok=True)
3458+
>>> df.to_csv('out.csv')
3459+
3460+
>>> from pathlib import Path
3461+
>>> filepath = Path('folder/subfolder/out.csv')
3462+
>>> filepath.parent.mkdir(parents=True, exist_ok=True)
3463+
>>> df_to_csv(filepath)
34533464
"""
34543465
df = self if isinstance(self, ABCDataFrame) else self.to_frame()
34553466

0 commit comments

Comments
 (0)