load_data¶
- pyhelpers.store.load_data(path_to_file, verbose=False, show_warning=True, prt_kwargs=None, raise_error=False, **kwargs)[source]¶
Loads data from a file.
- Parameters:
path_to_file (str | os.PathLike) – Pathname of the file; supported formats include Pickle, CSV, Microsoft Excel spreadsheet, JSON, Joblib, Feather, Parquet and GeoPackage.
verbose (bool | int) – Whether to print relevant information in console as the function runs; defaults to
False.show_warning (bool) – Whether to show a warning message if an unknown error occurs; defaults to
True.prt_kwargs (dict | None) – [Optional] Additional parameters for the function
pyhelpers.store._check_loading_path(); defaults toNone.raise_error (bool) – Whether to raise the provided exception; if
raise_error=False(default), the error will be suppressed.kwargs – [Optional] Additional parameters for one of the following functions:
load_pickle(),load_csv(),load_spreadsheets(),load_json(),load_joblib(),load_feather(),load_parquet(), orload_geopackage().
- Returns:
Data retrieved from the specified path
path_to_file.- Return type:
Any
Note
Example data can be referred to in the function
save_data().
Examples:
>>> from pyhelpers.store import load_data >>> from pyhelpers.dirs import cd >>> data_dir = cd("tests", "data") >>> dat_pathname = cd(data_dir, "dat.pickle") >>> pickle_dat = load_data(path_to_file=dat_pathname, verbose=True) Loading "./tests/data/dat.pickle" ... Done. >>> 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 >>> dat_pathname = cd(data_dir, "dat.csv") >>> csv_dat = load_data(path_to_file=dat_pathname, index_col=0, verbose=True) Loading "./tests/data/dat.csv" ... Done. >>> csv_dat Longitude Latitude City London -0.127647 51.507322 Birmingham -1.902691 52.479699 Manchester -2.245115 53.479489 Leeds -1.543794 53.797418 >>> dat_pathname = cd(data_dir, "dat.json") >>> json_dat = load_data(path_to_file=dat_pathname, verbose=True) Loading "./tests/data/dat.json" ... Done. >>> json_dat {'London': {'Longitude': -0.1276474, 'Latitude': 51.5073219}, 'Birmingham': {'Longitude': -1.9026911, 'Latitude': 52.4796992}, 'Manchester': {'Longitude': -2.2451148, 'Latitude': 53.4794892}, 'Leeds': {'Longitude': -1.5437941, 'Latitude': 53.7974185}} >>> dat_pathname = cd(data_dir, "dat.feather") >>> feather_dat = load_data(path_to_file=dat_pathname, index_col=0, verbose=True) Loading "./tests/data/dat.feather" ... Done. >>> feather_dat Longitude Latitude City London -0.127647 51.507322 Birmingham -1.902691 52.479699 Manchester -2.245115 53.479489 Leeds -1.543794 53.797418 >>> dat_pathname = cd(data_dir, "dat.joblib") >>> joblib_dat = load_data(path_to_file=dat_pathname, verbose=True) Loading "./tests/data/dat.joblib" ... Done. >>> joblib_dat LinearRegression()