I have a pandas data frame called df .
I want to save this in gzipped format. One way to do this:
import gzip import pandas df.save('filename.pickle') f_in = open('filename.pickle', 'rb') f_out = gzip.open('filename.pickle.gz', 'wb') f_out.writelines(f_in) f_in.close() f_out.close()
However, to do this, you must first create a file called filename.pickle . Is there a way to do this more directly, i.e. Without creating filename.pickle ?
When I want to load a data frame that was gzipped, I need to go through the same step of creating filename.pickle. For example, to read the file filename2.pickle.gzip , which is gzipped pandas, I know about the following method:
f_in = gzip.open('filename2.pickle.gz', 'rb') f_out = gzip.open('filename2.pickle', 'wb') f_out.writelines(f_in) f_in.close() f_out.close() df2 = pandas.load('filename2.pickle')
Can this be done without first creating filename2.pickle ?
Curious2learn
source share