请帮帮我,我不想从CSV文件中打印标题。
csvfile = open('testdata.csv', 'rU')
jsonfile = open('brofile.json', 'w')
fieldnames = {'Matric':[("studentName","dept","status")]}
reader = csv.DictReader( csvfile, fieldnames)
for row in reader:
json.dump(row, jsonfile)
jsonfile.write('\n')
预期输出
[2010CS01: { "Jones Doe", "Computer science", "paid"}]
[2010CS02: {"James Rug", "Computer Science", "Paid"}]
[2010AC01: {"Curtis Payne", "Accounting", "unpaid"}]
CSV文件:
Matric Name Department Status
2010CS01 Jones Doe Computer Science Paid
2010CS02 James Rug Computer Science Paid
2010AC01 Curtis Payne Accounting Unpaid