from datasets import DatasetBuilder, DownloadManager, DatasetInfo, Features, Value, SplitGenerator, Split import csv import os class WeatherDataset(DatasetBuilder): VERSION = "1.0.0" BUILDER_CONFIGS = [] def _info(self): return DatasetInfo( description="This dataset contains hourly weather information from 2023/3/19 to 2024/3/16 in ten major stations in the state of North Carolina.", features=Features({ "dt": Value("int64"), "main.temp": Value("float"), "main.feels_like": Value("float"), "main.pressure": Value("int64"), "main.humidity": Value("int64"), "main.temp_min": Value("float"), "main.temp_max": Value("float"), "wind.speed": Value("float"), "wind.deg": Value("int64"), "wind.gust": Value("float"), "clouds.all": Value("int64"), "latitude": Value("float"), "longitude": Value("float"), "date": Value("string"), "rain.1h": Value("float"), "weather_id": Value("int64"), "weather_main": Value("string"), "weather_description": Value("string"), "weather_icon": Value("string"), "city": Value("string"), "snow.1h": Value("float").nullable, "rain.3h": Value("float").nullable, }), supervised_keys=None, citation = """@misc{weather_dataset_2024, author = {Katherine Tian}, title = {Weather Dataset for NC City Analysis}, year = {23-24}, howpublished = {\url{https://github.com/yourusername/weather-dataset}} }""", ) def _split_generators(self, dl_manager: DownloadManager): data_dir = dl_manager.download_and_extract("https://huggingface.co/datasets/Katherinetian/weather_data_NC/raw/main/weather_data.csv") return [ SplitGenerator( name=Split.TRAIN, gen_kwargs={"filepath": os.path.join(data_dir, "weather_data.csv")}, ), ] def _generate_examples(self, filepath): with open(filepath, encoding="utf-8") as csv_file: reader = csv.DictReader(csv_file) for id_, row in enumerate(reader): # Process nullable fields row['snow.1h'] = float(row['snow.1h']) if row.get('snow.1h') else None row['rain.3h'] = float(row['rain.3h']) if row.get('rain.3h') else None # Convert fields to their appropriate types row['rain.1h'] = float(row['rain.1h']) yield id_, row