Datasets:
File size: 2,716 Bytes
2c8683d af5183d 2c8683d 6aa96d9 2c8683d |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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 |