一键多值字典写入CSV后格式错误
我想把这样的一个字典(即INFORMATION)写入CSV中,然后用了如下的代码,但是CSV里面格式却不对齐,新手求助,请各位指点指点。{'User_id': ['Cal', 'Jennifer', 'Ritesh', 'Gary', 'CK'], 'Date': [['09/03/18'], ['09/01/18'], ['08/29/18'], ['on'], ['08/12/18']]}
程序代码:
import csv with open('Acura_MDX.csv','a',newline='') as csvfile: fieldnames=['User_id','Date','Vehicle_type'] writer=csv.DictWriter(csvfile,fieldnames=fieldnames) for keyss in fieldnames: for ii in range(5): writer.writerow({keyss:INFORMATION[keyss][ii]})