如何将Pandas数据框保存到压缩的csv文件中? [英] how can I save a Pandas dataframe into a compressed csv file?

查看:96
本文介绍了如何将Pandas数据框保存到压缩的csv文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Pandas 0.18以 gz 格式加载了非常大的csv文件

I load a very large csv file in a gz format in Pandas 0.18 using

pd = pd.read_csv('myfile.gz')

毫不奇怪,将csv解压缩并加载到RAM中后,它将占用大量空间.但是,执行计算后,我仍然需要保存文件.

Without surprise, once the csv is unzipped and loaded into the RAM, it takes a lot of space. However, I still need to save my file after I perform my computations.

to_csv 是否可以以 gz 格式存储我的数据框?我在StackOverflow上发现的唯一与直接相关的问题3岁...

Can to_csv store my dataframe in a gz format? The only related question I found on StackOverflow is 3 year old...

推荐答案

您可以使用参数 compression ='gzip'

这篇关于如何将Pandas数据框保存到压缩的csv文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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