Skip to content

added a compression argument to to_csv to be sent to _get_handle #2636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
8 changes: 6 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ def _helper_csv(self, writer, na_rep=None, cols=None,
def to_csv(self, path_or_buf, sep=",", na_rep='', float_format=None,
cols=None, header=True, index=True, index_label=None,
mode='w', nanRep=None, encoding=None, quoting=None,
line_terminator='\n'):
line_terminator='\n', compression=None):
"""
Write DataFrame to a comma-separated values (csv) file

Expand Down Expand Up @@ -1380,6 +1380,10 @@ def to_csv(self, path_or_buf, sep=",", na_rep='', float_format=None,
file
quoting : optional constant from csv module
defaults to csv.QUOTE_MINIMAL
compression : string, optional
a string representing the compression to use in the output file,
currently only supports gzip and bz2 (see core.common._get_handle),
only used when the first argument is a filename
"""
if nanRep is not None: # pragma: no cover
import warnings
Expand All @@ -1391,7 +1395,7 @@ def to_csv(self, path_or_buf, sep=",", na_rep='', float_format=None,
f = path_or_buf
close = False
else:
f = com._get_handle(path_or_buf, mode, encoding=encoding)
f = com._get_handle(path_or_buf, mode, encoding=encoding, compression=compression)
close = True

if quoting is None:
Expand Down