/
bustarley
/
mini-crop-yield
Обзор
Документация
Войти
/
bustarley
/
mini-crop-yield
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
scripts/load_data.py
54 строки
2 KB
Дмитрий
init commit
17 июл 2026, 16:41
17 июл 2026, 16:41
5b1f142
Код
Авторство
О чём код?
import kagglehub import os import shutil from pathlib import Path def download_and_save_dataset(): print("Downloading dataset...") try: download_path = kagglehub.dataset_download("gurudathg/crop-yield-prediction-using-soil-and-weather") if not download_path or not os.path.exists(download_path): print("Error: Download failed - invalid path") return False if not os.listdir(download_path): print("Error: Downloaded dataset is empty") return False data_dir = Path("data") data_dir.mkdir(exist_ok=True) copied_count = 0 for item in os.listdir(download_path): src = os.path.join(download_path, item) if os.path.isfile(src): if item.endswith('.csv'): dst = data_dir / "raw.csv" else: dst = data_dir / item shutil.copy2(src, dst) copied_count += 1 elif os.path.isdir(src): dst = data_dir / item shutil.copytree(src, dst, dirs_exist_ok=True) copied_count += 1 if copied_count == 0: print("Error: No files were copied") return False print(f"Success: Dataset saved to {data_dir.absolute()}") print(f"Files copied: {copied_count}") return True except Exception as e: print(f"Error: {e}") return False if __name__ == "__main__": success = download_and_save_dataset() if not success: exit(1)