File size: 1,499 Bytes
bab61d9 |
1 2 3 4 5 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 33 34 35 36 37 38 |
import csv
import datasets
class GenericCSVLoader(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
description="Generic CSV loader script for Hugging Face Datasets.",
features=datasets.Features({
"RequestID": datasets.Value("string"),
"Boro": datasets.Value("string"),
"Yr": datasets.Value("string"),
"M": datasets.Value("string"),
"D": datasets.Value("string"),
"HH": datasets.Value("string"),
"MM": datasets.Value("string"),
"Vol": datasets.Value("string"),
"SegmentID": datasets.Value("string"),
"WktGeom": datasets.Value("string"),
"street": datasets.Value("string"),
"fromSt": datasets.Value("string"),
"toSt": datasets.Value("string"),
"Direction": datasets.Value("string")
}),
supervised_keys=None,
)
def _split_generators(self, dl_manager):
data_path = dl_manager.download_and_extract("sample_traffic.csv")
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_path})
]
def _generate_examples(self, filepath):
with open(filepath, newline="", encoding="utf-8") as f:
reader = csv.DictReader(f)
for i, row in enumerate(reader):
yield i, row
|