|
import pandas as pd |
|
import json |
|
|
|
|
|
df = pd.read_csv('train.csv') |
|
|
|
|
|
if len(df.columns) != 3: |
|
raise ValueError("The CSV file should have exactly 3 columns.") |
|
|
|
|
|
print(df.head()) |
|
|
|
with open('file.json', 'w') as wrfile: |
|
count = 0 |
|
for index, row in df.iterrows(): |
|
|
|
|
|
try: |
|
new_json = { |
|
"instruction": row['ref'], |
|
"input": "", |
|
"output": row['mr'] |
|
} |
|
except Exception as e: |
|
print(f'ๅ็้่ฏฏ: {e}') |
|
|
|
|
|
|
|
|
|
output = json.dumps(new_json, ensure_ascii=False) |
|
output = output + ',\n' |
|
print(output) |
|
wrfile.write(output) |
|
count += 1 |
|
|
|
print("count :", count) |
|
|
|
|