Dataset
The Dataset object in ydata-sdk is a schema-aware data structure built on pandas, providing a consistent interface for data manipulation, profiling, and synthetic data generation workflows. It wraps a pandas DataFrame and adds type management, missing-value tracking, and convenience methods used across the entire YData ecosystem.
The Dataset object integrates natively with pandas and numpy, allowing effortless conversion to and from both formats.
Key features
- Schema Awareness: Stores and maintains column metadata, variable types, and structure for enhanced data integrity.
- Seamless Integration: Easily converts to pandas DataFrames or numpy arrays for flexible data manipulation.
- In-Memory Processing: Designed for datasets that fit in memory, powered by pandas for reliable single-machine performance.
- Supports Data Preprocessing – Provides built-in utilities for type casting, sampling, filtering, and data transformation.
ydata.dataset.dataset.Dataset
Dataset class provides the interface to handle data within YData's package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
Union[DataFrame, ndarray]
|
The data to be manipulated. |
required |
schema
|
Optional[Dict]
|
Mapping of column names to variable types. |
None
|
sample
|
float
|
Fraction of the data to be sampled as the Dataset |
0.2
|
index
|
Optional[str]
|
Name of the column to be used as index, if any. This is an optional input, specially recommended for TimeSeries data. |
None
|
Properties
columns (list[str]): list of column names that are part of the Dataset schema nrows (int): number of rows from the Dataset ncols (int): number of columns shape (tuple): tuple of (nrows, ncols) memory_usage (int): total memory usage of the dataset in bytes nmissings (int): total number of missings in Dataset dtypes (Dict[str, str]): mapping of data type per column, either provided or inferred index (str): Returns the name of the index column
Magic Methods
columns
property
A list with the Dataset column names.
index
property
The name of the logical index column, if any.
loc
property
Label location based indexer for selection. Delegates to the underlying pandas DataFrame loc indexer.
df.loc["b"] df.loc["b":"d"]
memory_usage
property
A property that returns the total memory usage of the Dataset in bytes. Returns: memory_usage (int): Total memory usage of the Dataset in bytes.
ncols
property
Number of columns in the Dataset.
nmissings
property
Total number of missing values in the Dataset.
nrows
property
Number of rows in the Dataset.
schema
property
writable
A dictionary mapping column names to their VariableType.
Returns:
| Name | Type | Description |
|---|---|---|
schema |
dict
|
{column_name: VariableType} |
apply(function, axis=1, raw=False, args=None)
Apply a function along an axis of the Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
callable
|
Function to apply to each row. |
required |
axis
|
Union[int, str]
|
1/'columns' apply function to each row. 0/'index' apply function to each column is not supported. |
1
|
raw
|
bool
|
If True, the function receives numpy arrays instead of Series. |
False
|
args
|
Optional[Tuple]
|
Positional arguments to pass to function. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
df |
Dataset
|
A dataset object output of function. |
astype(column, vartype, format=None)
copy()
Copy a Dataset instance.
Returns:
| Name | Type | Description |
|---|---|---|
dataset |
Dataset
|
A new Dataset instance with the same schema and index. |
drop_columns(columns, inplace=False)
head(n=5)
infer_dtypes(schema=None)
missings()
Calculates the number of missing values per column in a Dataset. Returns: missings (pandas.Series): Missing value count per column.
query(query)
reorder_columns(columns)
sample(size, strategy='random', **strategy_params)
select_columns(columns, copy=True)
select_dtypes(include=None, exclude=None)
shape()
Return the (nrows, ncols) shape of the Dataset.
Returns:
| Name | Type | Description |
|---|---|---|
shape |
tuple
|
A tuple of (nrows, ncols). |
sort_values(by, ignore_index=True, inplace=False)
Sort the dataset by one or more columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
by
|
List[str]
|
Column(s) to sort by. |
required |
ignore_index
|
bool
|
Whether to reset the index after sorting. |
True
|
inplace
|
bool
|
Whether to sort in-place. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
dataset |
Dataset
|
Sorted dataset (if inplace is False). |
sorted_index(by)
tail(n=5)
to_numpy()
Converts the Dataset to a numpy ndarray.
Returns:
| Name | Type | Description |
|---|---|---|
dataset |
ndarray
|
The underlying data as a numpy array. |
to_pandas()
Converts the Dataset to a pandas DataFrame.
Returns:
| Name | Type | Description |
|---|---|---|
dataset |
DataFrame
|
The underlying pandas DataFrame. |
uniques(col)
update_types(dtypes)
Batch update data types for multiple columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtypes
|
list
|
List of dicts, each with 'column' and 'vartype' keys. |
required |