CSV (Comma-Separated Values) reader and writer.
Handles the plain-text tabular case: optional header row, any single-character delimiter, and a target column selected by index or by name. Values are parsed without pandas, so this loader has no third-party dependency.
Functions
load_csv(filepath: Union[str, Path], target_column: Union[int, str]=..., header: bool=True, delimiter: str=',') -> Dataset
Load data from CSV (Comma-Separated Values) files.
Standard CSV loader supporting headers, custom delimiters, and automatic target extraction.
Parameters
filepath
Union[str, Path]
Path to the CSV file to be loaded.
target_column
int or str
= -1
The column to treat as the target variable:
- •
-1: Use the last column - •
int: Use specific zero-based index - •
str: Use column name (requires header=True) - •
None: Do not extract a target (X will contain all columns)
header
bool
= True
Whether the first row of the CSV contains column names.
delimiter
str,'
The character used to separate columns in the file.
Returns
Dataset
Standardized dataset object containing data and metadata.
python
>>> from tuiml.datasets.loaders import load_csv
>>> data = load_csv('data.csv')
>>> X, y = data
>>> print(X.shape)
save_csv(filepath: Union[str, Path], data: np.ndarray, feature_names: Optional[List[str]]=None, target: Optional[np.ndarray]=None, target_name: str='target', delimiter: str=',')
Save data to CSV (Comma-Separated Values) format.
Parameters
filepath
Union[str, Path]
Output path where the CSV file will be saved.
data
np.ndarray
Feature matrix to save.
feature_names
List[str] or None
= None
Names for the features. If None, generic names like
col0, col1 will be used.
target
np.ndarray or None
= None
Target values (labels) to include in the output.
target_name
str
= "target"
The header name for the target column.
delimiter
str,'
The character used to separate columns in the file.
python
>>> import numpy as np
>>> from tuiml.datasets.loaders import save_csv
>>> X = np.random.rand(10, 2)
>>> save_csv('output.csv', X, feature_names=['f1', 'f2'])