繁体   English   中英

python-将多个标头写入csv文件

[英]python- writing multiple header to csv file

我真的很感激通过只写一次标题来帮助我解决这个错误

try:
    with open(save_folder + 'all.csv', 'a', newline='') as csvfile_new:
        spamwriter = csv.writer(csvfile_new, delimiter=',')
        for i in range(np.shape(csv_data)[0]): #Count through all rows in list and save to csv
            spamwriter.writerow(csv_data[i][:])

    print("Processing of file named {} is completed.".format(file))
except PermissionError:
    print("\n--- PERMISION ERROR ---")
    print("CSV FILE NAMED: {} COULD NOT BE PROCESSED".format(patient_id + '.csv'))
    print("PLEASE ENSURE THIS SPREADSHEET IS NOT BEING USED BY ANOTHER PROGRAM\n")

这就是我的文件看起来像csv 文件的方式

    with open(save_folder + 'all.csv', 'a', newline='') as csvfile_new:

    spamwriter = csv.writer(csvfile_new, delimiter=',')
    count = 0
    header_row =[]
    for i in csv_data: #Count through all rows in list and save to csv
        other_rows = []
        if count == 0:
            header_row.append(i)
            spamwriter.writerow(header_row)
            count = count+1
        other_rows.append(i)
        spamwriter.writerow(other_rows)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM