cj commited on
Commit ·
b6b4786
1
Parent(s): 5180197
add data
Browse files
file.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
main.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
# Read the CSV file into a DataFrame
|
| 5 |
+
df = pd.read_csv('train.csv')
|
| 6 |
+
|
| 7 |
+
# Check if the CSV file indeed has 3 columns
|
| 8 |
+
if len(df.columns) != 3:
|
| 9 |
+
raise ValueError("The CSV file should have exactly 3 columns.")
|
| 10 |
+
|
| 11 |
+
# Display the first few rows of the DataFrame to see your data
|
| 12 |
+
print(df.head())
|
| 13 |
+
|
| 14 |
+
with open('file.json', 'w') as wrfile:
|
| 15 |
+
count = 0
|
| 16 |
+
for index, row in df.iterrows():
|
| 17 |
+
#print(index, row['ref'], row['mr'])
|
| 18 |
+
# Create a new JSON object
|
| 19 |
+
try:
|
| 20 |
+
new_json = {
|
| 21 |
+
"instruction": row['ref'],
|
| 22 |
+
"input": "",
|
| 23 |
+
"output": row['mr']
|
| 24 |
+
}
|
| 25 |
+
except Exception as e:
|
| 26 |
+
print(f'发生错误: {e}')
|
| 27 |
+
#print("cttt cut ", name_parts)
|
| 28 |
+
# exit()
|
| 29 |
+
|
| 30 |
+
# Print the new JSON object
|
| 31 |
+
output = json.dumps(new_json, ensure_ascii=False)
|
| 32 |
+
output = output + ',\n'
|
| 33 |
+
print(output)
|
| 34 |
+
wrfile.write(output)
|
| 35 |
+
count += 1
|
| 36 |
+
|
| 37 |
+
print("count :", count)
|
| 38 |
+
# ... You can now further process or analyze your data ...
|
train.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|