| from datasets import DatasetBuilder, DownloadManager, DatasetInfo |
| import datasets |
| import os |
| import pandas as pd |
|
|
| class TradingDataset(datasets.GeneratorBasedBuilder): |
| |
| BUILDER_CONFIGS = [ |
| datasets.BuilderConfig(name="all", version=datasets.Version("1.0.0")), |
| datasets.BuilderConfig(name="stocks", version=datasets.Version("1.0.0")), |
| datasets.BuilderConfig(name="etfs", version=datasets.Version("1.0.0")) |
| ] |
|
|
| def _info(self): |
| return datasets.DatasetInfo( |
| |
| description="This is my custom dataset.", |
|
|
| |
| features=datasets.Features({ |
| "File": datasets.Value("string"), |
| "Date": datasets.Value("datetime"), |
| "Open": datasets.Value("float64"), |
| "High": datasets.Value("float64"), |
| "Low": datasets.Value("float64"), |
| "Close": datasets.Value("float64"), |
| "Adj Close": datasets.Value("float64"), |
| "Volume": datasets.Value("float64"), |
| }), |
| |
| |
| |
| supervised_keys=None, |
| |
| homepage="https://huggingface.co/datasets/sebdg/trading_data/", |
| citation="Your Citation Here", |
| ) |
|
|
| def _split_generators(self, dl_manager: DownloadManager): |
| """Returns SplitGenerators.""" |
| print('Split generators') |
| |
| |
| |
| |
| |
| |
| urls_to_download = {"data_file": "path/to/your/local/file.csv"} |
| downloaded_files = dl_manager.download_and_extract(urls_to_download) |
|
|
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| |
| gen_kwargs={ |
| "filepath": downloaded_files["data_file"], |
| "split": "train", |
| }, |
| ), |
| ] |
|
|
| def _generate_examples(self, filepath, split): |
| """Yields examples.""" |
| |
| print('Yielding examples') |
| data = pd.read_csv(filepath) |
| for id, row in data.iterrows(): |
| yield id, { |
| "File": row["File"], |
| "Date": row["Date"], |
| "Open": row["Open"], |
| "High": row["High"], |
| "Low": row["Low"], |
| "Close": row["Close"], |
| "Adj Close": row["Adj Close"], |
| "Volume": row["Volume"], |
| } |
|
|