| 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) | |