save_pickle

pyhelpers.store.save_pickle(pickle_data, path_to_pickle, verbose=False, **kwargs)

Save data to a Pickle file.

Parameters
  • pickle_data (any) – data that could be dumped by the built-in module pickle.dump

  • path_to_pickle (str or os.PathLike[str]) – path where a pickle file is saved

  • verbose (bool or int) – whether to print relevant information in console, defaults to False

  • kwargs – [optional] parameters of pickle.dump

Examples:

>>> from pyhelpers.store import save_pickle
>>> from pyhelpers.dirs import cd
>>> from pyhelpers._cache import example_dataframe

>>> pickle_dat = 1

>>> pickle_pathname = cd("tests\data", "dat.pickle")
>>> save_pickle(pickle_dat, pickle_pathname, verbose=True)
Saving "dat.pickle" to "tests\data\" ... Done.

>>> # Get an example dataframe
>>> pickle_dat = example_dataframe()
>>> pickle_dat
            Longitude   Latitude
City
London      -0.127647  51.507322
Birmingham  -1.902691  52.479699
Manchester  -2.245115  53.479489
Leeds       -1.543794  53.797418

>>> save_pickle(pickle_dat, pickle_pathname, verbose=True)
Updating "dat.pickle" at "tests\data\" ... Done.

See also