trading_data / trading_data.py
sebdg's picture
Update trading_data.py
c71a614 verified
Raw
History Blame
3.26 kB
from datasets import DatasetBuilder, DownloadManager, DatasetInfo
import datasets
import os
import pandas as pd
class TradingDataset(datasets.GeneratorBasedBuilder):
# Replace 'your_dataset_name' with an actual name for your dataset
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(
# This is the description that will appear on the datasets page.
description="This is my custom dataset.",
# datasets.features.FeatureConnectors
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"),
}),
# If there's a common (input, target) tuple from the features,
# specify them here. They'll get used if as_supervised=True in
# builder.as_dataset.
supervised_keys=None,
# Homepage of the dataset for documentation
homepage="https://huggingface.co/datasets/sebdg/trading_data/",
citation="Your Citation Here",
)
def _split_generators(self, dl_manager: DownloadManager):
"""Returns SplitGenerators."""
print('Split generators')
# If your dataset is hosted online, use the DownloadManager to download and extract it
# For local data, you can skip the DownloadManager and use the local paths directly
# For example, if your dataset is online:
# downloaded_files = dl_manager.download_and_extract("Your dataset URL")
# For local files, directly point to the file paths
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,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": downloaded_files["data_file"],
"split": "train",
},
),
]
def _generate_examples(self, filepath, split):
"""Yields examples."""
# Load the CSV file
print('Yielding examples')
data = pd.read_csv(filepath)
for id, row in data.iterrows():
yield id, {
"File": row["File"], # Adjust field names based on your CSV
"Date": row["Date"],
"Open": row["Open"],
"High": row["High"],
"Low": row["Low"],
"Close": row["Close"],
"Adj Close": row["Adj Close"],
"Volume": row["Volume"],
}