to_pickle()

When a Python object is pickled, it gets saved to disk. Pickling serializes the object first, before writing it. It involves converting objects such as lists, Dicts, DataFrames, and trained machine learning models into a character stream.

Let's convert the DataFrame we defined earlier into pickle format: 

df.to_pickle('pickle_filename.pkl')

It is also possible to compress pickle files before they are written. Compression schemes such as gzip, bz2, and xz are supported: 

df.to_pickle("pickle_filename.compress", compression="gzip")

By default, the compression type is inferred from the extension that's provided: 

df.to_pickle("pickle_filename.gz")

The read_pickle() function will deserialize the pickle file. Zip compression is only supported for reading a single file and not for writing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset