How to save a pandas dataframe in gzipped format directly?

后端 未结 4 2482
迷失自我
迷失自我 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:43

    You can dump dataframe into string using pickle.dumps and then write it on disk with import gzip

    file = gzip.GzipFile('filename.pickle.gz', 'wb', 3)
    file.write(pickle.dumps(df))
    file.close()
    

提交回复
热议问题