Python/Pandas create zip file from csv

最后都变了- 提交于 2019-12-14 00:18:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!