7b-viggo / main.py
cj
add data
b6b4786
raw
history blame contribute delete
No virus
1.07 kB
import pandas as pd
import json
# Read the CSV file into a DataFrame
df = pd.read_csv('train.csv')
# Check if the CSV file indeed has 3 columns
if len(df.columns) != 3:
raise ValueError("The CSV file should have exactly 3 columns.")
# Display the first few rows of the DataFrame to see your data
print(df.head())
with open('file.json', 'w') as wrfile:
count = 0
for index, row in df.iterrows():
#print(index, row['ref'], row['mr'])
# Create a new JSON object
try:
new_json = {
"instruction": row['ref'],
"input": "",
"output": row['mr']
}
except Exception as e:
print(f'ๅ‘็”Ÿ้”™่ฏฏ: {e}')
#print("cttt cut ", name_parts)
# exit()
# Print the new JSON object
output = json.dumps(new_json, ensure_ascii=False)
output = output + ',\n'
print(output)
wrfile.write(output)
count += 1
print("count :", count)
# ... You can now further process or analyze your data ...