Download InternVL-main/test_read.py from MallikaWy/project-backup: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/datasets/MallikaWy/project-backup/resolve/main/InternVL-main/test_read.py
- Command line
-
hf download hf://datasets/MallikaWy/project-backup/InternVL-main/test_read.py
-
curl -L -o test_read.py https://huggingface.co/datasets/MallikaWy/project-backup/resolve/main/InternVL-main/test_read.py
1.35 kB
| import json | |
| import os | |
| import pandas as pd | |
| data_list=[] | |
| n=0 | |
| with open("aaa.json", "r") as f: | |
| data=json.load(f) | |
| print(len(data)) | |
| def read_jsonl(path): | |
| with open(path, "r") as f: | |
| return [json.loads(line) for line in f] | |
| data_list=read_jsonl("aaa.jsonl" ) | |
| print(len(data_list)) | |
| def json_to_csv(input_json_file, output_csv_file): | |
| # 读取 JSON 文件 | |
| data = pd.read_json(input_json_file) | |
| # 将数据保存为 CSV 文件 | |
| data.to_csv(output_csv_file, index=False, encoding='utf-8') | |
| print(f"✅ 文件已成功转换为 CSV,保存为: {output_csv_file}") | |
| # 示例用法 | |
| input_json_file = "aaa.json" # 输入的 JSON 文件路径 | |
| output_csv_file = "aaa1.csv" # 输出的 CSV 文件路径 | |
| json_to_csv(input_json_file, output_csv_file) | |
| def jsonl_to_csv(input_jsonl_file, output_csv_file): | |
| # 读取 JSONL 文件,每行是一个独立的 JSON 对象 | |
| data = pd.read_json(input_jsonl_file, lines=True) | |
| # 将数据保存为 CSV 文件 | |
| data.to_csv(output_csv_file, index=False, encoding='utf-8') | |
| print(f"✅ 文件已成功转换为 CSV,保存为: {output_csv_file}") | |
| # 示例用法 | |
| input_jsonl_file = "aaa.jsonl" # 输入的 JSONL 文件路径 | |
| output_csv_file = "aaa2.csv" # 输出的 CSV 文件路径 | |
| jsonl_to_csv(input_jsonl_file, output_csv_file) |