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:
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()