File size: 815 Bytes
744b2e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pandas as pd
from csv_jsonl import JSONLinesDictWriter

def csv_to_jsonl(csv_file_path, output_file_path):
    # Load CSV file into a pandas DataFrame
    df = pd.read_csv(csv_file_path)

    # Convert DataFrame to a list of dictionaries (JSON-like format)
    data_list = df.to_dict(orient='records')

    # Save the data to JSONL file using csv_jsonl library
    with open(output_file_path, "w", encoding="utf-8-sig") as _fh:
        writer = JSONLinesDictWriter(_fh)
        writer.writerows(data_list)

if __name__ == "__main__":
    # Replace 'metadata.csv' with the actual file name and path
    input_csv_file = "test/metadata.csv"
    # Replace 'metatrain.jsonl' with the desired output file name and path
    output_jsonl_file = "metadata.jsonl"

    csv_to_jsonl(input_csv_file, output_jsonl_file)