问题
Is anyone can provide example how to create zip file from csv file using Python/Pandas package? Thank you
回答1:
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.
回答2:
In response to Stefan's answer, add '.csv.gz' for the zip csv file to work
df.to_csv('my_file.csv.gz', compression='gzip')
Hope that helps
来源:https://stackoverflow.com/questions/37754165/python-pandas-create-zip-file-from-csv