Download replace_null.py from chanyo111/xasoss: direct link, hf CLI and curl.
- Browser
- Download file 583 Bytes
-
https://huggingface.co/datasets/chanyo111/xasoss/resolve/main/replace_null.py
- Command line
-
hf download hf://datasets/chanyo111/xasoss/replace_null.py
-
curl -L -o replace_null.py https://huggingface.co/datasets/chanyo111/xasoss/resolve/main/replace_null.py
583 Bytes
| import json, glob | |
| from pathlib import Path | |
| # 当前目录及子目录 | |
| files = list(Path(".").rglob("*.jsonl")) + list(Path(".").rglob("*.csv")) | |
| # 转成字符串路径 | |
| files = [str(f) for f in files] | |
| for file in files: | |
| with open(file, "r", encoding="utf-8") as f: | |
| data = [json.loads(line) for line in f] | |
| # 替换 null | |
| for d in data: | |
| for k in d: | |
| if d[k] is None: | |
| d[k] = "" | |
| # 写回 | |
| with open(file, "w", encoding="utf-8") as f: | |
| for line in data: | |
| f.write(json.dumps(line, ensure_ascii=False) + "\n") | |