save_pickle

pyhelpers.store.save_pickle(data, path_to_file, verbose=False, **kwargs)[source]

Save data to a Pickle file.

Parameters:
  • data (Any) – Data that could be dumped by the built-in module pickle.dump.

  • path_to_file (str | os.PathLike) – Path where a pickle file is saved.

  • verbose (bool | 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