Skip to content

data_loader

Load Built-In Datasets for Testing and Classification

load_data

load_data(dataset='series_synthetic')

Loads sample datasets bundled with PyTrendy.

This provides quick access to preloaded datasets for testing and demonstration. Available datasets include synthetic time series and trend classification examples.

Parameters:

  • dataset

    (str, default: 'series_synthetic' ) –

    Name of the dataset to load. Options include:

    • 'series_synthetic': A synthetic time series with embedded trends.
    • 'classes_signals': Reference signals for classifying trends as gradual or abrupt.

Returns:

  • DataFrame

    pd.DataFrame: A pandas DataFrame containing the requested dataset.

Source code in pytrendy/io/data_loader.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def load_data(dataset: str = 'series_synthetic') -> pd.DataFrame:
    """
    Loads sample datasets bundled with PyTrendy.

    This provides quick access to preloaded datasets for testing and demonstration.
    Available datasets include synthetic time series and trend classification examples.

    Args:
        dataset (str, optional):
            Name of the dataset to load. Options include:

            - `'series_synthetic'`: A synthetic time series with embedded trends.
            - `'classes_signals'`: Reference signals for classifying trends as gradual or abrupt.

    Returns:
        pd.DataFrame:
            A pandas DataFrame containing the requested dataset.
    """

    options = ['classes_signals', 'series_synthetic']
    if dataset not in options:
        print(f'{dataset} is not a valid dataset to load from PyTrendy. Please try either of {options}')

    dir_path = Path(__file__).resolve().parent
    file_path = dir_path / "data" / f"{dataset}.csv"
    df = pd.read_csv(file_path)
    return df