gsplot.data.load_file#
Functions
|
Loads structured data from a file or iterable source using the specified parameters. |
- load_file(f, delimiter=',', skip_header=0, skip_footer=0, unpack=True, **kwargs)[source]#
Loads structured data from a file or iterable source using the specified parameters.
This function provides a flexible interface for loading data with NumPy’s genfromtxt. It captures and processes the passed parameters, allowing for customized file loading options, such as handling delimiters, skipping headers/footers, and unpacking columns.
- Parameters:
f (
str
,os.PathLike
,Iterable[str]
, orIterable[bytes]
) – The file path, file-like object, or iterable source from which to load data.delimiter (
str
orNone
, optional) – The string used to separate values. If None, any whitespace is treated as a delimiter (default is “,”).skip_header (
int
, optional) – The number of lines to skip at the beginning of the file (default is 0).skip_footer (
int
, optional) – The number of lines to skip at the end of the file (default is 0).unpack (
bool
, optional) – Whether to unpack columns into separate arrays (default is True).**kwargs (
Any
) – Additional keyword arguments to pass to NumPy’s genfromtxt.
Notes
This function utilizes the ParamsGetter to retrieve bound parameters and the CreateClassParams class to handle the merging of default, configuration, and passed parameters.
- Returns:
The loaded data as a NumPy array.
- Return type:
- Raises:
ValueError – If the file cannot be loaded or parsed correctly.
Examples
>>> import gsplot as gs >>> data = gs.load_file("data.csv", delimiter=",", skip_header=1, unpack=False) >>> print(data) array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]])
>>> data = gs.load_file(["1,2,3", "4,5,6", "7,8,9"], delimiter=",", unpack=True) >>> print(data) [array([1.0, 4.0, 7.0]), array([2.0, 5.0, 8.0]), array([3.0, 6.0, 9.0])]