Spaces:
Sleeping
Sleeping
Download env/tasks/task_easy.py from gauravnetes/datacleaning-env: direct link, hf CLI and curl.
- Browser
- Download file 1.74 kB
-
https://huggingface.co/spaces/gauravnetes/datacleaning-env/resolve/main/env/tasks/task_easy.py
- Command line
-
hf download hf://spaces/gauravnetes/datacleaning-env/env/tasks/task_easy.py
-
curl -L -o task_easy.py https://huggingface.co/spaces/gauravnetes/datacleaning-env/resolve/main/env/tasks/task_easy.py
1.74 kB
| import pandas as pd | |
| import numpy as np | |
| import os | |
| TASK_NAME = "fix_missing_values" | |
| DIFFICULTY = "easy" | |
| DESCRIPTION = "Fill missing values in a customer dataset using appropriate strategies per column." | |
| DIRTY_PATH = os.path.join(os.path.dirname(__file__), "../datasets/easy_dirty.csv") | |
| CLEAN_PATH = os.path.join(os.path.dirname(__file__), "../datasets/easy_clean.csv") | |
| def generate_datasets(): | |
| np.random.seed(42) | |
| n = 100 | |
| clean = pd.DataFrame({ | |
| "age": np.random.randint(18, 70, n).astype(float), | |
| "salary": np.random.randint(30000, 120000, n).astype(float), | |
| "gender": np.random.choice(["Male", "Female"], n), | |
| "score": np.round(np.random.uniform(0, 100, n), 2), | |
| "city": np.random.choice(["Delhi", "Mumbai", "Bangalore"], n), | |
| }) | |
| dirty = clean.copy() | |
| for col in ["age", "salary", "score"]: | |
| idx = np.random.choice(n, 15, replace=False) | |
| dirty.loc[idx, col] = np.nan | |
| for col in ["gender", "city"]: | |
| idx = np.random.choice(n, 10, replace=False) | |
| dirty.loc[idx, col] = np.nan | |
| os.makedirs(os.path.dirname(DIRTY_PATH), exist_ok=True) | |
| dirty.to_csv(DIRTY_PATH, index=False) | |
| clean.to_csv(CLEAN_PATH, index=False) | |
| print(f"[datasets] easy_dirty.csv and easy_clean.csv generated.") | |
| def get_task(): | |
| if not os.path.exists(DIRTY_PATH): | |
| generate_datasets() | |
| return { | |
| "name": TASK_NAME, | |
| "difficulty": DIFFICULTY, | |
| "description": DESCRIPTION, | |
| "dirty_path": DIRTY_PATH, | |
| "clean_path": CLEAN_PATH, | |
| "allowed_operations": [ | |
| "fill_nulls", | |
| "submit" | |
| ], | |
| "max_steps": 10, | |
| } | |
| if __name__ == "__main__": | |
| generate_datasets() |