File size: 1,072 Bytes
b6b4786
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 ...