How to save a pandas dataframe in gzipped format directly?

后端 未结 4 2506
迷失自我
迷失自我 2021-02-19 18:24

I have a pandas data frame, called df.

I want to save this in a gzipped format. One way to do this is the following:

import gzip
import pand         


        
4条回答
  •  礼貌的吻别
    2021-02-19 18:55

    Better serialization with compression has recently been added to Pandas. (Starting in pandas 0.20.0.) Here is an example of how it can be used:

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

    For more information, such as different forms of compression available, check out the docs.

提交回复
热议问题