Python/Pandas从CSV创建zip文件 [英] Python/Pandas create zip file from csv

查看:535
本文介绍了Python/Pandas从CSV创建zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以提供示例如何使用Python/Pandas软件包从csv文件创建zip文件吗? 谢谢

解决方案

使用

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

从文档中

compression:字符串,可选 一个字符串,代表要在输出文件中使用的压缩,允许的值为"gzip","bz2","xz",仅当第一个 参数是文件名

请参见此处.

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

解决方案

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.

这篇关于Python/Pandas从CSV创建zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆