| import json | |
| import csv | |
| from pathlib import Path | |
| import pandas as pd | |
| def save_json_lines(records, path): | |
| p = Path(path) | |
| p.parent.mkdir(parents=True, exist_ok=True) | |
| with open(p, 'w', encoding='utf-8') as f: | |
| for r in records: | |
| f.write(json.dumps(r) + "\n") | |
| def load_json_lines(path): | |
| with open(path, 'r', encoding='utf-8') as f: | |
| for line in f: | |
| if line.strip(): | |
| yield json.loads(line) | |
| def save_csv(df, path): | |
| p = Path(path) | |
| p.parent.mkdir(parents=True, exist_ok=True) | |
| df.to_csv(p, index=False) | |