Read_ComprehensionQA / jsonl2csv.py
KashiwaByte's picture
add dataset
fe1fffd
raw
history blame contribute delete
664 Bytes
import json
import csv
def convert_jsonl_to_csv(jsonl_file, csv_file):
with open(jsonl_file, 'r',encoding='utf-8') as file:
json_data = [json.loads(line) for line in file]
if len(json_data) > 0:
fields = list(json_data[0].keys())
with open(csv_file, 'w', newline='',encoding='utf-8') as file:
writer = csv.DictWriter(file, fieldnames=fields)
writer.writeheader()
for data in json_data:
writer.writerow(data)
# 使用示例
jsonl_file = 'Read_Comperhension50k.jsonl'
csv_file = 'Read_Comperhension50k.csv'
convert_jsonl_to_csv(jsonl_file, csv_file)