Search code examples
pythoncsvpandaszipcompression

Python/Pandas create zip file from csv


Is anyone can provide example how to create zip file from csv file using Python/Pandas package? Thank you


Solution

  • Use

    df.to_csv('my_file.gz', compression='gzip')
    

    From the docs:

    compression : string, optional a string representing the compression to use in the output file, allowed values are ‘gzip’, ‘bz2’, ‘xz’, only used when the first argument is a filename

    See discussion of support of zip files here.