Skip to content

df.to_csv ignores compression when provided with a file handle #21227

Closed
@guinny65

Description

@guinny65

Code at issue

with open(outputfile, "w") as file_handle:
    df2.to_csv(file_handle, compression='gzip')

Problem description

The written file is not gzip compressed.

Expected Output

The output should be a gzip compressed csv file. Similar to what is obtained when using:

df2.to_csv('/path/to/file.csv.gz',compression='gzip')

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO CSVread_csv, to_csvOutput-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions