File size: 664 Bytes
7c93e9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)